Case : I need to loop over an array in PHP and remove elements based on some condition.

Solution:

print_r($arr);
foreach($arr as $key => $val)
{
  if($val == 'xyz')
  {
    unset($arr[$key]);
  }
}
print_r($arr);

Works great!

Advertisements