Re: How to check value in multidimensional array

From: Date: Sat, 18 Nov 2006 21:46:38 +0000
Subject: Re: How to check value in multidimensional array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-244836@lists.php.net to get a copy of this message
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>

« previous php.general (#244836) next »