Getting unique values from 2 arrays

前端 未结 7 1959
借酒劲吻你
借酒劲吻你 2020-12-03 11:01

I have 2 arrays that I\'m trying to get the unique values only from them. So I\'m not just trying to remove duplicates, I\'m actually trying to remove both duplicates.

7条回答
  •  庸人自扰
    2020-12-03 11:37

    Another good solution is this:

    $array1 = array(10, 15, 20, 25);

    $array2 = array(10, 15, 100, 150);

    $output = array_diff(array_merge($array1, $array2), array_intersect($array1, $array2));

    // $output will be (20, 25, 100, 150);

提交回复
热议问题