How to check value in multidimensional array
| From: | Erik Gyepes | Date: | Sat, 18 Nov 2006 18:46:28 +0000 |
| Subject: | How to check value in multidimensional array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-244833@lists.php.net to get a copy of this message | ||
Hi guys,
I have an array with navigation items like that:
$navigationItemArr = array("Home"=>"home",
"Profile"=>"profile",
"Photogallery"=>"photogallery",
"Contact"=>array("contact","subsection")
);
How can I check for a value in this array?
I tried something like this:
.
.
..for.... $i++.. { // there is a normal for cycle, this is just an illustration
.
.
if(in_array($bodyVariablePiece[$i], $navigationItemArr)) {
echo "$bodyVariablePiece[$i] [$i] - ok<br />";
}
else {
echo "$bodyVariablePiece[$i] [$i] - error<br />";
}
.
.
}
.
.
* in $bodyVariablePiece are values extracted from URL like - home, profile, photogallery, contact
Everything works except contact - there it show error. So what is the correct way to check values in multidimensional arrays? Is it possible with in_array() function?
Thanks,
Erik