3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a = array(); for($i = 0; $i < pow(10, 6); $i++) { $a[$i] = array( md5(microtime(true)) ); } $sum = 0; $times['for']['before'] = microtime(true); for($j = 0; $i < count($a); $i++) { $sum += 1000; } $times['for']['after'] = microtime(true); unset($sum); $sum = 0; $times['foreach']['before'] = microtime(true); foreach($a as $k) { $sum += 1000; } $times['foreach']['after'] = microtime(true); unset($sum); $t_for = $times['for']['after'] - $times['for']['before']; $t_foreach = $times['foreach']['after'] - $times['foreach']['before']; echo "<pre>"; var_dump(array($times, 'is for faster than foreach?' => $t_for < $t_foreach, $t_for, $t_foreach));
Output for 5.3.0 - 5.4.27
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 2097152 bytes) in /in/UObb0 on line 5
Process exited with code 255.