Reputation: 33
I have an array, $search_results
. Each key has multiple elements. I also have a single column array called $outofstock
. If any of the elements within a particular key of $search_results
exactly match any of the entries in $outofstock
, I would like to remove the key, and re-arrange the key structure, so as to not have a gap in key ordering - and then create a new array of the same name: $search_results
.
I've tried a few solutions found here - namely
But I can't seem to get them to match the text exactly and then re-create the array, while using array_filter
to remove the entries I need to remove.
Upvotes: 1
Views: 141
Reputation: 4534
You can loop through one array and remove the index where you find string you are searching for.
for($i=0;i$<count($outofstock);$i++){
foreach($search_result as $k=>$v){
if($outofstock[$i]==$v){
unset($search_result[$k]);
}
}
}
$search_result = array_values($search_result);
Upvotes: 1