[SOLVED] Array Question ( should be simple )

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

[SOLVED] Array Question ( should be simple )

Post 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.
?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

foreach($array as $key=>$element)
  if($element==0)
     unset($array[$key]);
?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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
Post Reply