note 87060 added to function.array-search
| From: | michi7x7 at osu1 dot php dot net | Date: | Mon, 17 Nov 2008 19:32:05 +0000 |
| Subject: | note 87060 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146633@lists.php.net to get a copy of this message | ||
If you exit the function whith "return", there is no need to break ;)
i would write it like this:
<?php
function array_search_recursive($needle, $haystack, $path=array())
{
foreach($haystack as $id => $val)
{
$path2=$path;
$path2[] = $id;
if($val === $needle)
return $path2;
else if(is_array($val))
if($ret = array_search_recursive($needle, $val, $path2))
return $ret;
}
return false;
}
$array = array(
"a" => array(
"b" => array("c"),
"d" => array("e"),
),
"f" => array( "g", "h"),
);
var_dump(array_search_recursive("e", $array));
?>
var dump prints a array: (a, d, 0)
----
Server IP: 192.35.244.50
Probable Submitter: 62.47.221.175
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/87060
Del: integrated -- https://master.php.net/note/delete/87060/integrated
Del: useless -- https://master.php.net/note/delete/87060/useless
Del: bad code -- https://master.php.net/note/delete/87060/bad+code
Del: spam -- https://master.php.net/note/delete/87060/spam
Del: non-english -- https://master.php.net/note/delete/87060/non-english
Del: in docs -- https://master.php.net/note/delete/87060/in+docs
Del: other reasons-- https://master.php.net/note/delete/87060
Reject -- https://master.php.net/note/reject/87060
Search -- https://master.php.net/manage/user-notes.php