用下述方法代替array_diff()
public function array_diff_repeat($arr1, $arr2) {
$temp_arr1 = [];
$temp_arr2 = [];
foreach ($arr1 as $arr1_key => $arr1_id) {
$index_id = array_search($arr1_id, $arr2, true);
if($index_id !== false) {
unset($arr1[$arr1_key]);
unset($arr2[$index_id]);
} else {
array_push($temp_arr1, $arr1_id);
}
}
foreach ($arr2 as $arr2_key => $arr2_id) {
$index_id = array_search($arr2_id, $arr1, true);
if($index_id !== false) {
unset($arr1[$arr2_key]);
unset($arr2[$index_id]);
} else {
array_push($temp_arr2, $arr2_id);
}
}
return ['temp_arr1' => $temp_arr1, 'temp_arr2' => $temp_arr2];
}
|