- var_dump: documentation ( source)
- microtime: documentation ( source)
- array_filter: documentation ( source)
- range: documentation ( source)
<?php
$a = range(0, 10000);
$time = microtime(true);
$b = array_filter($a, function($el) { return $el % 2 === 0; });
var_dump(microtime(true) - $time);
$b = [];
$time = microtime(true);
foreach ($a as $el) {
if ($el % 2 === 0) {
$b[] = $el;
}
}
var_dump(microtime(true) - $time);