note 114140 deleted from function.in-array by sobak
| From: | sobak@php.net | Date: | Sat, 25 Feb 2017 06:05:23 +0000 |
| Subject: | note 114140 deleted from function.in-array by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208843@lists.php.net to get a copy of this message | ||
Note Submitter: manuel at sunred dot org
----
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;
}
?>