Jump to content

Help getting the differences between 2 arrays


TheBrandon

Recommended Posts

Hello all,

 

I have 2 arrays containing numbers; I just need to extract the unique ones from the first array. For example, right now I have this:

  Quote
existing_Array:

Array ( [31] => 31 [34] => 34 [41] => 41 [43] => 43 [44] => 44 [62] => 62 [63] => 63 [64] => 64 [71] => 71 [97] => 97 [233] => 233 [234] => 234 [291] => 291 )

submitted_Array:

Array ( [31] => 3 [34] => 2 [41] => 3 [43] => 1 [44] => 2 [63] => 1 [64] => 2 [71] => 6 [97] => 5 [233] => 3 [234] => 1 [291] => 2 )

 

I want this:

  Quote
new_Array:

Array ( [62] => 62 )

 

I thought array_diff did this exactly, but when I do:

$new_Array = array_diff($existing_Array, $submitted_Array);

 

It's giving me this:

  Quote
Array ( [31] => 31 [34] => 34 [41] => 41 [43] => 43 [44] => 44 [62] => 62 [63] => 63 [64] => 64 [71] => 71 [97] => 97 [233] => 233 [234] => 234 [291] => 291 )

 

Can someone help me get this to work?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.