php method to merge different array elements: 1. Create a PHP sample file; 2. Use "array_keys(array_flip($a) array_flip($b) array_flip($c));" to multiple Just merge the arrays to remove duplicates.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How does php merge different array elements?
Multiple array deduplication
array_keys(array_flip($arr1)+array_flip($arr2))
array_keys() function returns a new array containing all the key names in the array.
If the second parameter is provided, only the key name with the key value is returned.
Return a new array containing all the key names in the array:
<?php $a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander"); print_r(array_keys($a)); ?>
Running results:
Array ( [a] => red [b] => green ) Array ( [0] => Volvo [1] => BMW [2] => Toyota )
Techniques for merging and deduplicating multiple arrays
$a = array('1001','1002'); $b = array('1002','1003','1004'); $c = array('1003','1004','1005'); $d = array_keys(array_flip($a) + array_flip($b) + array_flip($c));
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to merge different array elements in php. For more information, please follow other related articles on the PHP Chinese website!