note 28219 added to function.array-search
| From: | w dot neyndorff at xs4all dot nl | Date: | Mon, 06 Jan 2003 14:16:36 +0000 |
| Subject: | note 28219 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41730@lists.php.net to get a copy of this message | ||
I needed a function that searches for the key in the array and not for the value. I wanted to be
able to search for keys in a multidimensional array so i made the function recursive:
function getElementvalue($array,$element) {
global $return;
while(list($key,$val) = each($array)) {
if (is_array($val)) getElementvalue($val,$element);
else if (trim($key)==$element) $return = trim($val);
}
return $return;
}
//Usage: $var will get the value of key "KeyToLookFor"
$var = getElementvalue($array,"KeyToLookFor")
--
http://www.php.net/manual/en/function.array-search.php
http://master.php.net/manage/user-notes.php?action=edit+28219
http://master.php.net/manage/user-notes.php?action=delete+28219
http://master.php.net/manage/user-notes.php?action=reject+28219