3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testBase = array_fill(0, 100000, 'testdata'); echo "Test array count: " . count($testBase) . PHP_EOL; for($x = 0; $x < 10; $x++ ) { echo "Test #$x" . PHP_EOL; /* foreach test */ $testCopy = array(); $before = microtime(true); foreach ($testBase as $key => $value) { $testCopy[$key] = $value . 'asdasd'; } $after = microtime(true); $dif = $after - $before; echo "foreach test ($before, $after): $dif" . PHP_EOL; /* array_walk test */ $testCopy = $testBase; $before2 = microtime(true); array_walk($testCopy, function(&$value, $key) { $value = $value . 'qweqwe'; }); $after2 = microtime(true); $dif2 = $after2 - $before2; echo "array_walk test ($before2, $after2): $dif2" . PHP_EOL; }

preferences:
31.62 ms | 402 KiB | 5 Q