3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(); $l = 10000; for($i = 0; $i< 10000; $i++) { $array[$i] = md5($i); } $copy = $array; $start = microtime(true); for($i = 0; $i< 10000; $i++) { $copy[$i] = $copy[$i] . ' x'; } echo "for:" . microtime(true) - $start; $copy = $array; $start = microtime(true); foreach ($copy as $i => $item) { $copy[$i] = $item . ' x'; } echo "foreach (ohne ref):" . microtime(true) - $start; $copy = $array; $start = microtime(true); foreach ($copy as &$item) { $item .= ' x'; } echo "foreach (ohne ref):" . microtime(true) - $start; $copy = $array; $start = microtime(true); array_walk($copy, function (&$item, $i) { $item .= ' x'; }); echo "array_walk (mit ref):" . microtime(true) - $start; $copy = $array; $start = microtime(true); $copy = array_map(function (&$item, $i) { $x .= ' x'; }, $copy); echo "array_map (mit ref):" . microtime(true) - $start;

preferences:
31.18 ms | 402 KiB | 5 Q