note 80902 added to function.array-search
| From: | mjaning at gmail dot com | Date: | Wed, 06 Feb 2008 07:42:54 +0000 |
| Subject: | note 80902 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135813@lists.php.net to get a copy of this message | ||
Hi! Based on Chris function, I made another to simplify code and improve diferents features...
With this function you can:
- Filter Key and Values recursively
- Call function many times using previows result
- Final result always will be an array numeric index contenting a value or sigle array
key=>value.
Thanks for PHP!
<?php
function array_search_recursive($needle, $haystack, $nodes=array())
{
foreach ($haystack as $key1=>$value1)
{
if (is_array($value1))
$nodes = array_search_recursive($needle, $value1, $nodes);
elseif (($key1 == $needle) or ($value1 == $needle))
$nodes[] = array($key1=>$value1);
}
return $nodes;
}
$arg[] = array("column1"=>"Class3");
$arg[] = array("column2"=>"Class1");
$arg[] = array("column3"=>"Class3");
$arg[] = array("column4"=>"Class4");
$arg[] = array("column4"=>"Class3");
$arg[] = "column3";
$filter = array_search_recursive("Class3",$arg);
echo "<hr>";var_dump($filter);
$filter = array_search_recursive("column3",$filter);
echo "<hr>";var_dump($filter);
?>
----
Server IP: 208.69.120.35
Probable Submitter: 74.222.192.96
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/80902
Del: integrated -- https://master.php.net/note/delete/80902/integrated
Del: useless -- https://master.php.net/note/delete/80902/useless
Del: bad code -- https://master.php.net/note/delete/80902/bad+code
Del: spam -- https://master.php.net/note/delete/80902/spam
Del: non-english -- https://master.php.net/note/delete/80902/non-english
Del: in docs -- https://master.php.net/note/delete/80902/in+docs
Del: other reasons-- https://master.php.net/note/delete/80902
Reject -- https://master.php.net/note/reject/80902
Search -- https://master.php.net/manage/user-notes.php