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

这是代码:

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()获取数据,然后遍历它,以便可以对其执行另一个查询,该查询实际上将操纵数据库。

有任何想法吗?

最佳答案

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;
}

关于php - PHP:迭代其他函数和输出结果的函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6893083/

10-10 14:59