<?php
function array_remove1($array, $value) {
$key = array_search($value, $array);
if ($key === false)
return false;
unset($array[$key]);
return true;
}
function array_remove2($array, $value) {
array_diff($array, [$value]);
}
function test($function) {
static $max = 9999;
$array = range(0, $max);
$value = random_int(0, $max);
$start = microtime(true);
$function($array, $value);
return microtime(true) - $start;
}
$results = [];
$lessCount = $equallyCount = $moreCount = 0;
foreach (range(0, 499) as $index) {
$first = test('array_remove1');
$second = test('array_remove2');
$cmp = $first <=> $second;
$results[] = [$cmp, $first, $second];
if ($cmp == -1)
$lessCount++;
elseif ($cmp == 0)
$equallyCount++;
elseif ($cmp == 1)
$moreCount++;
}
var_dump($lessCount, $equallyCount, $moreCount, $results);