PHP merge arrays with only NOT DUPLICATED values

前端 未结 5 1956
青春惊慌失措
青春惊慌失措 2020-11-29 06:03

I need to merge two arrays into 1 array but what I need is to remove before the main data they b oth have in common (duplicated values i mean), I need only unique values whe

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 06:50

    Faster solution:

    function concatArrays($arrays){
        $buf = [];
        foreach($arrays as $arr){
            foreach($arr as $v){
                $buf[$v] = true;
            }
        }
        return array_keys($buf);
    }
    
    
    $array = concatArrays([$array1, $array2]);
    

提交回复
热议问题