1

Hello i am trying to return the differences between two arrays but i am gettig this error that i do not understand, this is my code:

$unMatched = array_diff($matchedTickets, $cart['tickets']);

These are the two arrays:

$cartTickets:

array (size=1)
  0 => 
    array (size=5)
      'id' => int 13
      'class' => string 'Regular' (length=7)
      'description' => string 'Lorem ipsum dolor' (length=17)
      'fee' => int 100
      'quantity' => int 1

$matchedTickets:

array (size=1)
  0 => 
    array (size=3)
      'id' => int 13
      'class' => string 'Regular' (length=7)
      'fee' => float 100

Can somebody please tell me what i am doing wrong here?

11
  • 1
    What you're doing wrong is confusing json with PHP arrays Commented Sep 20, 2015 at 16:05
  • No they are actually both arrays (at least the first one is) they are convertered to json when i return them. Commented Sep 20, 2015 at 16:06
  • 1
    Then perhaps you should actually show us the value of the arrays.... var_dump() them to show what they actually contain.... showing us the json encoding is simply confusing the issue Commented Sep 20, 2015 at 16:07
  • 1
    So is $cart['tickets'] an array or an object? Use var_dump() and it will tell you Commented Sep 20, 2015 at 16:10
  • 1
    Yes i just did, updated my post Commented Sep 20, 2015 at 16:11

1 Answer 1

1

I had to add the index 0 to each of them to get it to work. I dont know why they're like that, but it works now.

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.