PHP:迭代另一个函数的结果并输出的函数
看起来这很简单,但是,我遇到了一个问题:
代码如下:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
getValidCustomers
不返回任何内容,也许您的意思是:getValidCustomers
doesn't return anything, maybe you mean this:getValidCustomers()
不会返回任何内容 - 它只是回显将
return $getCustomers
添加到getValidCustomers()
的末尾getValidCustomers()
doesn't return anything - it just echoesAdd
return $getCustomers
to the end ofgetValidCustomers()
将
return $getCustomers;
添加到getValidCustomers()
:DAdd
return $getCustomers;
togetValidCustomers()
:D