Page 1 of 1

[SOLVED] Array Question ( should be simple )

Posted: Wed Nov 19, 2003 5:42 pm
by infolock
Ok, I was wondering. Is there anyway you can call to check if an array has a certain value ( such as NULL or 0 ), to delete that array from your list, so that you are just retaining the arrays with values != what you specify ? I've looked with array_filter and array_search, but i can't seem to do what I am wanting.. Any help on this would be appreciated.


Code: Select all

<?php

for($i=0; $i<40; $i++)
{
    if ($bob[$i] != '0')
           $foo[$i] = $bob[$i];
}
?>
see, i know I can do something like that, but i'd rather not have to define another array, as it just slows the code down...

maybe I should just do something where a switch statement asks if Case ' > 0' to do something... i'll have to look that up.
?>

Posted: Wed Nov 19, 2003 5:49 pm
by Weirdan

Code: Select all

foreach($array as $key=>$element)
  if($element==0)
     unset($array[$key]);
?

Posted: Wed Nov 19, 2003 5:51 pm
by infolock
well, isn't that with something like $needle and $haystack where you are using a multidimensional array?


edit :

n/m, that's exactly what i was looking for :D

thanks