php Getting the 'new' values in an array
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-03-12T22:29:29Z
Indexed on
2010/03/12
22:37 UTC
Read the original article
Hit count: 147
Trying to learn about php's arrays today.
I have a set of arrays like this:
$a = array (
0 => array ( 'value' => 'America', ),
1 => array ( 'value' => 'England', ),
2 => array ( 'value' => 'Australia', ),
)
$b = array (
0 => array ( 'value' => 'America', ),
1 => array ( 'value' => 'England', ),
2 => array ( 'value' => 'Canada', ),
)
I need to get the 'new' subarrays that array b brings to the table.
ie, I need to return array ( 'value' => 'Canada', )
I thought I could first merge $a+$b and then compare the result to $a.
$merge = array_merge($a,$b);
$result = array_diff($merge,$a);
But somehow that does not work. It returns array()
How come? And thanks!
© Stack Overflow or respective owner