How can I unset the keys in one array where the values contained in a second array match the values in the first array?
Actual array:
$fruits = array('Banana','Cherry','Orange','Apple');
Elements I want to remove:
$remove = array('Banana','Apple');
Need to return:
$array = array('Cherry','Orange');
I know it's possible to remove each one with unset
, but I'm looking to make it in one line with two array.
Thanks.
Take a look at this function link
$arrayWithoutTheDesiredElements = array_diff($originalArr, $toRemoveArray)
EDIT:
for your case: $array = array_diff($fruits, $remove);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.