Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设getCustomers函数以 array() 的形式从数据库中获取客户。由于数据库位于实时系统中,因此getCustomers结果可能会有所不同。php如何处理这两个代码:
getCustomers
for ($i=0; $i<count(getCustomers());++$i){ ... }
foreach (getCustomers() as $key => $value) { ... }
在getCustomers()执行每个代码后调用一次还是在每个循环中调用?
getCustomers()
在您的 for() 循环中,每次迭代都会再次调用 getCustomers(),count(); 也是如此。在 foreach() 循环中它只被调用一次