1

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.

4

1 回答 1

1

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);
于 2013-03-30T18:34:41.840 回答