I have two multidimensional arrays. the first one is:
Array
(
[0] => Array
(
[username] => J1
[fullname] => John1
)
[1] => Array
(
[username] => K1
[fullname] => Kate
)
[2] => Array
(
[username] => P1
[fullname] => Peter
)
[3] => Array
(
[username] => M1
[fullname] => Mary
)
)
and the second one is:
Array
(
[0] => Array
(
[username] => J1
[fullname] => John33
)
[1] => Array
(
[username] => L1
[fullname] => Lucas
)
[2] => Array
(
[username] => P1
[fullname] => Paul
)
)
I want to compare the two arrays using only their username option in order to get the elements of first array which are not included in second array (comparing only the usernames).
so i want a new array like the following:
Array
(
[0] => Array
(
[username] => K1
[fullname] => Kate
)
[1] => Array
(
[username] => M1
[fullname] => Mary
)
)
Any help?? thanks a lot!!!
You could do something like this in PHP >= 5.5.0:
$result = array_diff_key(array_column($array1, null, 'username'),
array_column($array2, null, 'username')
);
0 comments:
Post a Comment