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.

Community
  • 1
  • 1
  • 1
    This question does not show any research effort. It is important to **do your homework**. Tell us what you found and ***why*** it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. [FAQ](http://stackoverflow.com/questions/how-to-ask). – John Conde Mar 30 '13 at 18:09
  • My apologies - this is my first post to stack overflow! I've added a bit more information about what I've tried so far. I hope this helps. – MANWWEBSITE Mar 30 '13 at 18:18

1 Answers1

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);
thaJeztah
  • 27,738
  • 9
  • 73
  • 92
justnajm
  • 4,422
  • 6
  • 36
  • 56
  • I think you're on the right path, but the out of stock goods are still being displayed on the page. Is this code case sensitive? Also I think a small typo at the second $i. Edit: let me make sure the mysql connection to the out of stock database is working before I jump to conclusions – MANWWEBSITE Mar 30 '13 at 18:55
  • Just a few changes and it's now working: THNAKS!! ` for($i=0;$i $data) { if ($data['soda'] == $blacklist[$i]) { unset($search_results[$index]); } } } ` – MANWWEBSITE Mar 30 '13 at 21:57