note 85686 added to function.array-search
| From: | s0i0m at dreamevilconcepts dot com | Date: | Fri, 12 Sep 2008 09:39:04 +0000 |
| Subject: | note 85686 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144358@lists.php.net to get a copy of this message | ||
I wrote a better array_search_recursive function. The other functions listed work and will evaluate
to true, however, they loop through the stack even after the needle is found: so this function will
take the overhead off the cpu =P
<?php
function array_search_recursive($needle, $haystack)
{
foreach ($haystack as $k => $v)
{
for ($i=0; $i<count($v); $i++)
if ($v[$i] === $needle)
{
return true;
break;
}
}
}
$access['admin'] = array('nick1');
$access['voice'] = array('nick2', 'nick3');
if (array_search_recursive('nick3', $access))
echo 'yes';
print_r($access);
?>
I wrote this for an access list that I have implemented into an IRC bot. See more interesting stuff
at dreamevilconcept's forum.
----
Server IP: 92.48.100.16
Probable Submitter: 92.1.182.133
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/85686
Del: integrated -- https://master.php.net/note/delete/85686/integrated
Del: useless -- https://master.php.net/note/delete/85686/useless
Del: bad code -- https://master.php.net/note/delete/85686/bad+code
Del: spam -- https://master.php.net/note/delete/85686/spam
Del: non-english -- https://master.php.net/note/delete/85686/non-english
Del: in docs -- https://master.php.net/note/delete/85686/in+docs
Del: other reasons-- https://master.php.net/note/delete/85686
Reject -- https://master.php.net/note/reject/85686
Search -- https://master.php.net/manage/user-notes.php