comparing execution speed of some php functions
for loop took
for()
loop using count()
took 20.86401 ms
for()
loop Not using count()
took 7.09796 ms
using count() means:
for ($i = 1; $i < count($myarr); ++ $i) {
..
where as foreach() loop:
foreach()
took 11.16920 ms
foreach()
with KEY took 12.35318 ms
these both are done on same array and their respective execution time is shown both for
and foreach
are language constructs and their execution speed will be more so you cannot notice much more difference unless you are using them on an array with thousands of records.