Пример в песочнице:
sandbox.onlinephpfunctions.com/code/c67bfe3d0aef9d...$arr1 = [
['id' =>1,'number' => 7],
['id' =>2,'number' => 8],
['id' =>3,'number' => 9],
['id' =>4,'number' => 10],
['id' =>5,'number' =>11],
];
$arr2 = [
['id' =>2,'number' => 7],
['id' =>2,'number' => 8],
['id' =>3,'number' => 9],
['id' =>4,'number' => 10],
];
//Надо выбрать все повторяющиеся значения
/**
* результат должен быть таким
$arr2 = [
['id' =>2,'number' => 8],
['id' =>3,'number' => 9],
['id' =>4,'number' => 10],
];
*/
$start = microtime();
$result3 = array_uintersect($arr1 , $arr2,function($a,$b){
if ($a['id']===$b['id'] && $a['number']===$b['number']) {
return 0;
}
return $a['id'] > $b['id'] ? 1:-1;
});
$end = microtime();
$time3 = $end - $start;
var_dump($result3,'time:'.$time3);
Вывод:
array(2) {
[2]=>
array(2) {
["id"]=>
int(3)
["number"]=>
int(9)
}
[3]=>
array(2) {
["id"]=>
int(4)
["number"]=>
int(10)
}
}
string(24) "time:0.00010299999999996"
Где
['id' => 2, 'number' => 8]
?Что с ним не так?