Re: How to check value in multidimensional array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am Samstag, 18. November 2006 22:08 schrieb Erik Gyepes:
> Oliver Block wrote:
> > Am Samstag, 18. November 2006 19:46 schrieb Erik Gyepes:
> >
> > What exactly do you need to do? You should read the manual too, at
>
> I would like to check if the value is really in the array, if it is not
> then I would like do some other things. (so not check if it is an array
> or not, as in your example) But my iteration not worked in
> multidimensional arrays.

>>$navigationItemArr = array("Home"=>"home",
>>                  "Profile"=>"profile",
>>                  "Photogallery"=>"photogallery",
>>                  "Contact"=>array("contact","subsection")
>>                  );

foreach($navigationItemArr as $k => $v) {
   if(is_array($v) {
      /* $v is array */
      foreach($v as $kk => $vv) {
          /* $kk hold the keys, $vv the associated values */
      }
  } else {
      /* $v is no array*/
  }
}

If you have to handle deeper nesting, i.e. $vv can hold arrays too, you should 
use a recursion. If only $v can hold an array and not $vv the above should 
work.

Regards,

Oliver


-- 
Leben ist mehr als ... 
<http://www.nak-nrw.de/index.php?id=71>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux