I have two arrays:
$A = array('a','b','c','d')
$c = array('b','c','e','f')
I want to get a new array containing items not in array $A
. So it would be:
$result = array('e','f');
because 'e'
and 'f'
are not in $A
.
I have two arrays:
$A = array('a','b','c','d')
$c = array('b','c','e','f')
I want to get a new array containing items not in array $A
. So it would be:
$result = array('e','f');
because 'e'
and 'f'
are not in $A
.
Use array_diff
print_r(array_diff($c, $A));
returnsUse
array_diff
for this task. As somewhat annoying it does not return all the differences between the two arrays. Only the elements from the first array passed which are not found in any other array passed as argument.array_diff()
Pseduo Code for General Implementation
Disclaimer: Not familiar with PHP, other answers indicate there are a lot quicker ways of doing this :)
Loop through your first array: