note 85796 deleted from function.in-array by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 21:38:05 +0000 |
| Subject: | note 85796 deleted from function.in-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156491@lists.php.net to get a copy of this message | ||
Note Submitter: Kureal at kkooporation dot de
----
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.