PHP:迭代另一个函数的结果并输出的函数

发布于 2024-11-27 00:31:45 字数 733 浏览 2 评论 0原文

看起来这很简单,但是,我遇到了一个问题:

代码如下:

function getValidCustomers() {
    global $db;
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;");
    foreach($getCustomers as $customer) {
        echo $customer['CustomerID']."\n";
    }
}

function updateValidCustomers() {
    $customers = getValidCustomers();
    for ($i = 0; $i < sizeof($customers); $i++) {
        echo "DEBUG: $customers[$i]\n";
    }
}

updateValidCustomers();

基本上,现在的输出是 CustomerID 列表(来自 updateValidCustomers())。我只想 updateValidCustomers()getValidCustomers() 获取数据,然后循环遍历它,以便我可以对其运行另一个查询来实际操作数据库。

有什么想法吗?

Seems like this would be pretty simple, however, I'm running into an issue:

Here's the code:

function getValidCustomers() {
    global $db;
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;");
    foreach($getCustomers as $customer) {
        echo $customer['CustomerID']."\n";
    }
}

function updateValidCustomers() {
    $customers = getValidCustomers();
    for ($i = 0; $i < sizeof($customers); $i++) {
        echo "DEBUG: $customers[$i]\n";
    }
}

updateValidCustomers();

Basically, the output right now is a list of the CustomerIDs (from updateValidCustomers()). I just want updateValidCustomers() to get the data from getValidCustomers() and then loop through it, so that I can run another query on it that will actually manipulate the database.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

单调的奢华 2024-12-04 00:31:45

getValidCustomers 不返回任何内容,也许您的意思是:

function getValidCustomers() {
    global $db;
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;");
    foreach($getCustomers as $customer) {
        echo $customer['CustomerID']."\n";
    }
    return $getCustomers;
}

getValidCustomers doesn't return anything, maybe you mean this:

function getValidCustomers() {
    global $db;
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;");
    foreach($getCustomers as $customer) {
        echo $customer['CustomerID']."\n";
    }
    return $getCustomers;
}
沫离伤花 2024-12-04 00:31:45

getValidCustomers() 不会返回任何内容 - 它只是回显

return $getCustomers 添加到 getValidCustomers() 的末尾

getValidCustomers() doesn't return anything - it just echoes

Add return $getCustomers to the end of getValidCustomers()

恏ㄋ傷疤忘ㄋ疼 2024-12-04 00:31:45

return $getCustomers; 添加到 getValidCustomers() :D

Add return $getCustomers; to getValidCustomers() :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文