19
在下面的代碼:在foreach循環中使用函數是否緩存結果或每次調用函數?
function a(){
echo 'a';
return array(1,2,3,4);
}
foreach(a() as $t){
echo $t;
}
我們可以看到()被調用一次,它似乎返回值緩存...
但後來我看到this debate (see comments on the question)我這麼想嗎?
嘗試將其更改爲'for($ a = 0; $ a <= count(a()); $ a ++)'並查看得到的結果:) – 2009-12-12 01:58:51