0

I have two arrays

Array1:

Array ( [0] => Array ( [0] => 3 [1] => 1 [2] => 4 ) [1] => Array ( [0] => 1 [1] => 6 ) )

Array2:

Array ( [0] => 1 [1] => 3 [2] => 2 )

I used array_diff for comparing and getting the difference values, but the same key is coming ie.,

array_diff(Array1,Array2)

returns Array([0] =>3 [2] => 4)

but is there any other way to get difference and having result like

Array([0] =>3 [1] => 4)..

2
  • 1
    You need to clarify a bit. What result are you expecting / do you want? Commented Feb 18, 2011 at 4:25
  • Any other method other than array_diff()(because it returns result along with key) for getting difference between two arrays..I want result as Array([0] =>3 [1] => 4) instead of Array([0] =>3 [2] => 4) Commented Feb 18, 2011 at 4:30

1 Answer 1

2

Assuming you've got array_diff working on the multidimensional array somehow, but from the docs:

This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff($array1[0], $array2[0]);.

Use array_values around it.

array_values(array_diff($array1, $array2));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.