In PHP, you can use the array_merge_recursive() function to merge arrays without duplication; this function will not overwrite the key name when processing two or more array elements with the same key name. Instead, multiple values with the same key name are recursively formed into an array.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the array_merge_recursive() function Implement merged arrays without deduplication.
array_merge_recursive() function merges one or more arrays into one array.
When two or more array elements have the same key name, this function will not overwrite the key name, but will recursively form multiple values with the same key name into an array.
Syntax:
array_merge_recursive(array1,array2,array3...)
Example:
<?php $a1=array("a"=>"red","b"=>"green"); $a2=array("c"=>"blue","b"=>"yellow"); $arr=array_merge_recursive($a1,$a2); var_dump($arr); ?>
Output result:
Recommended learning: "PHP video tutorial"
The above is the detailed content of How to merge php arrays without duplicates. For more information, please follow other related articles on the PHP Chinese website!