yandex
loader

please wait

  • Vikrant Srivastava Mar-14-2019 05:53:35 AM ( 1 week ago )

     

    I have two arrays like below;

    array1 =  {
               [0]=> 'A'
               [1]=> 'B'
               [2]=> 'C'
              }
    
    array2 =  {
               [0]=> 'B'
               [1]=> 'C'
               [2]=> 'D'
              }

    I want to compare these two arrays and get the difference. What I need return is like this;

    result = { [0]=> 'A' [1]=> 'D' }
    I thought I could use array_diff, but it compares key AND value as a pair. I want to compare ONLY values. How can I do that?

  • Vanshika Bhatt Mar-14-2019 05:55:20 AM ( 1 week ago )

    This should work -

    array_diff(array_merge($a, $b), array_intersect($a, $b))

    Checking difference between all merged and all common.

Please login

Similar Discussion

Recommended For You