OK, so I went off and measured it --
Test This And This And, uh, This
--------------------------- ---------------------------- ----------------------------
Setup Setup Setup
---------------------------- ---------------------------- ----------------------------
$i = array_fill(0,1000,'1'); $j = array_fill(0,1000,'1'); $j = array_fill(0,1000,'1');
$c = 0; $d = 0; $e = 0;
--------------------------- ---------------------------- ---------------------------
Code Under Test Code Under Test Code Under Test
--------------------------- ------------------------------ --------------------------
foreach ($i as $v) foreach (array_keys($j) as $k) foreach ($i as &$v)
{ $c+= $v; } { $d+= $j[$k]; } { $e+= $v; }
--------------------------- ------------------------------ -------------------------
Tear Down Tear Down Tear Down
--------------------------- ----------------------------- -------------------------
print "c = $c"; print "d = $d"; print "e = $e";
---------------------------- ----------------------------- --------------------------
Test for repetitions. 10000
---------------------------- ----------------------------- -------------------------
c = 10000000 d = 10000000 e = 10000000
---------------------------- ----------------------------- -------------------------
Ran in 1.8540189266205 Ran in 4.0039160251617 Ran in 1.9633851051331
--------------------------- ----------------------------- -------------------------
Winner -0.10936617851257 Looser 2.0405309200287 2nd Best 0
--------------------------- ---------------------------- -------------------------
Looks like foreach ($a as $v) is much better than array_keys and that using &v is in the middle.