note 85796 added to function.in-array
| From: | Kureal at kkooporation dot de | Date: | Thu, 18 Sep 2008 07:46:40 +0000 |
| Subject: | note 85796 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144503@lists.php.net to get a copy of this message | ||
A notice to the, by alishanovin [at] hotmail. [dot] com released, in_array wrapper function:
You should use Pre-Increment, e.g. instead of "$i++" -> "++$i".
Pre-Incrementing is prooved to be 10 % faster, which makes a search-trip in a
Thousand-Dimension-Array a quite faster.
Changed Version:
<?php
function in_wildarray($needle, $haystack, $case_sensitive=true) {
$is_wild = (!strpos($needle,"*")) ? false : true;
$needles = ($is_wild) ? explode("*", $needle) : array();
$needle = ($case_sensitive) ? $needle : strtolower($needle);
for($i=0, $req = count($haystack);$i < $req; ++$i) {
$haystack_str = ($case_sensitive) ? $haystack[$i] : strtolower($haystack[$i]);
if ($is_wild) {
$found = false;
for($x=0, $req = count($needles); $x < $req;++$x) {
$needle_index = strpos($haystack_str, trim($needles['x']));
$found = (!$needle_index) ? false : ($haystack_str = substr($haystack_str, 0,
$needle_index ? true : false));
}
if ($found) return true;
} elseif (!$is_wild && $haystack_str == $needle) {
return true;
}
}
return false;
}
?>
--
Kenan Sulayman
Application Designer,
KurealCorporation inc.
----
Server IP: 217.160.72.57
Probable Submitter: 77.185.126.201
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/85796
Del: integrated -- https://master.php.net/note/delete/85796/integrated
Del: useless -- https://master.php.net/note/delete/85796/useless
Del: bad code -- https://master.php.net/note/delete/85796/bad+code
Del: spam -- https://master.php.net/note/delete/85796/spam
Del: non-english -- https://master.php.net/note/delete/85796/non-english
Del: in docs -- https://master.php.net/note/delete/85796/in+docs
Del: other reasons-- https://master.php.net/note/delete/85796
Reject -- https://master.php.net/note/reject/85796
Search -- https://master.php.net/manage/user-notes.php