PHP - Merging two arrays into one array (also Remove Duplicates)

后端 未结 6 1133
野的像风
野的像风 2020-11-27 02:51

Hi I\'m Trying to merge two arrays and also want to remove duplicate values from final Array.

Here is my Array 1:

Array
    (
    [0] => stdClass          


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 03:03

    Merging two array will not remove the duplicate you can try the below example to get unique from two array

    $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
    $a2=array("e"=>"red","f"=>"green","g"=>"blue");
    
    $result=array_diff($a1,$a2);
    print_r($result);
    

提交回复
热议问题