# Recommended: "php method to merge arrays and remove duplicates: 1. Use the "array_merge" method or the " " symbol to merge arrays; 2. Use the "array_unique" function to merge arrays and remove duplicates.
//1.单数组去重复 array_unique($arrTest)//2.多数组去重复 array_keys(array_flip($arr1)+array_flip($arr2))
$arr1 = [1,2,3,4,5]; $arr2 = [1,2,3,6,7]; $arr3 = ['0'=>1,'1'=>2,'2'=>3,'3'=>4,'4'=>5]; $arr4 = ['0'=>1,'1'=>2,'2'=>3,'3'=>6,'4'=>7]; $arr5 = ['0'=>1,'a'=>2,'b'=>3,'c'=>4,'4'=>5]; $arr6 = ['0'=>1,'a'=>2,'c'=>3,'d'=>6,'4'=>7]; dump(array_merge($arr1, $arr2)); dump($arr1+$arr2); dump(array_keys(array_flip($arr1)+array_flip($arr2))); echo '<br>'; dump(array_merge($arr3, $arr4)); dump($arr3+$arr4); dump(array_keys(array_flip($arr3)+array_flip($arr4))); echo '<br>'; dump(array_merge($arr5, $arr6)); dump($arr5+$arr6);
The above is the detailed content of php merge arrays and remove duplicates. For more information, please follow other related articles on the PHP Chinese website!