0

i'm trying a way to remove from a multidimensional array, all the elements equal to another multidimensional array.

For example, i've these two arrays;

$array1 = Array ( [0] => Array ( [item1] => 3017, [item2] => 7 ), [1] => Array ( [item1] => 3018, [item2] => 4 ), [2] => Array ( [item1] => 3020, [item2] => 9 ), [3] => Array ( [item1] => 3024, [item2] => 5 ) ) 

and

$array2 = Array ( [0] => Array ( [item1] => 3017, [item2] => 7 ), [1] => Array ( [item1] => 3018, [item2] => 200 ), [2] => Array ( [item1] => 3020, [item2] => 300 ), [3] => Array ( [item1] => 3024, [item2] => 5 ) ) 

The difference beetween these two arrays is the value of [item2] in element [1] and [2].

I want get an array that contains only the different values of the first array. In my case, should be:

array_diff = array( [1] => Array ( [item1] => 3018, [item2] => 4 ), [2] => Array ( [item1] => 3020, [item2] => 9 ) )
Vardar
  • 1
  • 3

1 Answers1

0

Use json comparison ;)

$jsonDiff = array_diff(array_map('json_encode', $array1), array_map('json_encode', $array2));
$arrayDiff = array_map('json_decode', $diff);

regards.

fxlacroix
  • 557
  • 4
  • 18