为什么在 for 循环中使用变量比某些函数输出更快


Why is using a variable in a for loop faster than some function output?

在Symfony

博客上,为了支持Symfony更快,有人提到

for ($i = 0; $i<count($my_array); $i++)

for ($i = 0, $count = count($my_array); $i<$count; $i++)

他们提到的原因是"因为我们测量了"。但是,在上述两种方法中,后者速度更快的原因究竟是什么?

第一个 'for' 计算每次迭代的 $my_array 计数。第二个"for"计算一次计数。