- array_map: documentation ( source)
- microtime: documentation ( source)
- number_format: documentation ( source)
<?php
$entries = [];
for($i = 0; $i < 100000; $i++) {
$entries[] = ['id' => $i];
}
$t = microtime(true);
$res = array_map(function($entry) { return $entry['id']; }, $entries);
$t = microtime(true) - $t;
echo 'array_map() took ' . number_format($t, 3) . ' seconds';
$t = microtime(true);
$res = [];
foreach($entries as $entry) {
$res[] = $entry['id'];
}
$t = microtime(true) - $t;
echo "\n";
echo 'foreach took ' . number_format($t, 3) . ' seconds';