note 94601 added to function.array-key-exists
| From: | Darkless at seznam dot cz | Date: | Fri, 13 Nov 2009 17:17:48 +0000 |
| Subject: | note 94601 added to function.array-key-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162874@lists.php.net to get a copy of this message | ||
a bit upgraded multi_array_key_exists function
@param needle string to be searched in keys
@param haystack array to be searched in
@return false when it was not found or string structured by name of keys devided by ":"
eg $arrays = array ('first' => array ( 'one'=> 'anything'));
for multi_array_key_exists('one',$arrays) it returns:
"first:one" by explode you can then write sth like $array[$path[0]][$path[1]]...
<?php
function multi_array_key_exists($needle, $haystack) {
foreach ($haystack as $key=>$value) {
if ($needle===$key) {
return $key;
}
if (is_array($value)) {
if(multi_array_key_exists($needle, $value)) {
return $key . ":" . multi_array_key_exists($needle, $value);
}
}
}
return false;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.70.93.164
----
Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php
Edit -- https://master.php.net/note/edit/94601
Del: integrated -- https://master.php.net/note/delete/94601/integrated
Del: useless -- https://master.php.net/note/delete/94601/useless
Del: bad code -- https://master.php.net/note/delete/94601/bad+code
Del: spam -- https://master.php.net/note/delete/94601/spam
Del: non-english -- https://master.php.net/note/delete/94601/non-english
Del: in docs -- https://master.php.net/note/delete/94601/in+docs
Del: other reasons-- https://master.php.net/note/delete/94601
Reject -- https://master.php.net/note/reject/94601
Search -- https://master.php.net/manage/user-notes.php