Reputation: 586
So lets say we have two arrays as such :
$x = array(
"id" => 12,
"name" => "Joe",
"surname" => "Murphy",
"age" => 52
);
$y = array(
"id" => 12,
"name" => "Joe",
"surname" => "Murphy",
"age" => 53
);
function key_compare_func($key1, $key2)
{
if ($key1 == $key2)
return 0;
else if ($key1 > $key2)
return 1;
else
return -1;
}
var_dump(array_intersect_ukey($x, $y, 'key_compare_func'));
This would return all matching elements from $x
array(4) {
["id"]=> int(12)
["name"]=> string(3) "Joe"
["surname"]=> string(6) "Murphy"
["age"]=> int(52)
}
I need to get only ["age"]=> int(52)
I looked at these, but none seem to offer this sort of functionality, unless I missed something :
array_udiff_assoc, array_uintersect_assoc, array_uintersect_uassoc,
array_udiffarray_uintersect, array_udiff_uassoc
Upvotes: 0
Views: 41
Reputation: 1674
http://php.net/manual/en/function.array-diff-assoc.php
var_dump(array_diff_assoc($x, $y));
Upvotes: 1