2

I am not able to compare Multi-Dimension Array:

Lets Say I have two array as follows!

Array 1:

Array
    (
        [0] => Array
            (
                [a] => 12XXYYZZ
                [b] => 30
                [c] => 12
            )

        [1] => Array
            (
                [a] => 12SSYYZZ
                [b] => 66
                [c] => 44
            )
        [2] => Array
            (
                [a] => 12EEYYZZ
                [b] => 66
                [c] => 56
            )

    )

Array 2:

Array
    (
        [0] => Array
            (
                [a] => 12XXYYZZ
                [b] => 30
                [c] => 12
            )

        [1] => Array
            (
                [a] => 12SSYYZZ
                [b] => 66
                [c] => 44
            )


    )

I am trying to compare this two array and find what are the sub array not present in array 2;

Note: I tried Array DIFF but not working for Multi-Dimension Array.

DonOfDen
  • 3,968
  • 11
  • 62
  • 112
  • 2
    possible duplicate of [Multidimensional array diff](http://stackoverflow.com/questions/16359322/multidimensional-array-diff) – Roopendra Nov 25 '13 at 09:30

1 Answers1

1

You can use serialize to provide comparison, for example:

$result = array_map(
   'unserialize', 
   array_diff(
      array_map('serialize', $one),
      array_map('serialize', $two)
));

-but note, that it this case keys values and their order will matter. Alternatively, you can use array_udiff like follows:

$result = array_udiff($one, $two, function($x, $y)
{
   return strcasecmp(serialize($x), serialize($y));
});
Alma Do
  • 37,009
  • 9
  • 76
  • 105