note 104148 deleted from language.types.array by danbrown
| From: | danbrown@php.net | Date: | Thu, 26 May 2011 17:50:01 +0000 |
| Subject: | note 104148 deleted from language.types.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180056@lists.php.net to get a copy of this message | ||
Note Submitter: szikra dot istvan at freemail dot hu
----
I had to fix Ganpat Thakur version because it was bugging me.
Here's my function to deep search for keys:
<?php
function array_get_key_val($key, $heystack) {
// if (is_array($heystack))
foreach ($heystack as $k => $v) { /// loop through the array
if ($k == $key) return $v; /// found key, return with it
if (is_array($v)) { /// search in sub-heystack
$ret = array_get_key_val($key, $v);
if ($ret) return $ret; /// found, return
} /// not found, continue searching
}
return false; /// sorry searched everywhere :( :)
}
/// test
$b=array("a"=>array(), "b"=>2);
?>