note 28219 deleted from function.array-search by didou
| From: | didou@php.net | Date: | Tue, 16 Dec 2003 09:31:49 +0000 |
| Subject: | note 28219 deleted from function.array-search by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62029@lists.php.net to get a copy of this message | ||
Note Submitter: w.neyndorff@xs4all.nl
----
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")