note 114140 added to function.in-array
| From: | manuel at sunred dot org | Date: | Wed, 15 Jan 2014 21:00:53 +0000 |
| Subject: | note 114140 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198244@lists.php.net to get a copy of this message | ||
If you are looking for a faster in_array function but still need the strict feature with which the
type of element will be considered the following simple function might help you.
<?php
function fast_in_array($needle, array $haystack, $strict = false)
{
$c = count($haystack);
if($strict !== true)
{
for($i = 0; $i < $c; $i++)
if($haystack[$i] == $needle)
return true;
}
else
{
for($i = 0; $i < $c; $i++)
if($haystack[$i] === $needle)
return true;
}
return false;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/114140
Del: integrated -- https://master.php.net/note/delete/114140/integrated
Del: useless -- https://master.php.net/note/delete/114140/useless
Del: bad code -- https://master.php.net/note/delete/114140/bad+code
Del: spam -- https://master.php.net/note/delete/114140/spam
Del: non-english -- https://master.php.net/note/delete/114140/non-english
Del: in docs -- https://master.php.net/note/delete/114140/in+docs
Del: other reasons-- https://master.php.net/note/delete/114140
Reject -- https://master.php.net/note/reject/114140
Search -- https://master.php.net/manage/user-notes.php