- array_map: documentation ( source)
- microtime: documentation ( source)
- array_keys: documentation ( source)
- range: documentation ( source)
- array_walk: documentation ( source)
<?php
$iter = 1000;
$array = range(0, $iter);
$function = function($val, $key) {};
$t = microtime(true);
for($i = 0; $i < $iter; $i++)
{
array_walk($array, $function);
}
echo 'array_walk '.($walk = microtime(true) - $t);
$t = microtime(true);
for($i = 0; $i < $iter; $i++)
{
array_map($function, $array, array_keys($array));
}
echo ', array_map '.($map = microtime(true) - $t);
echo ', '.(100 - $walk / $map * 100).'%';