note 80447 added to function.array-search
| From: | phpawe at aweawe dot cjb dot net | Date: | Wed, 16 Jan 2008 16:29:56 +0000 |
| Subject: | note 80447 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135142@lists.php.net to get a copy of this message | ||
In many examples here strtolower() appears inside a loop so I guess this would be a good time to
repeat something which all programmers should know: DON'T make useless calculations inside a
loop since doing something O(n) times can become a lot more costly then doing it O(1) times.
The following function would do a case insensitive search in a given array:
public static function array_isearch($str, $array){
$str = strtolower($str);
foreach ($array as $k => $v) if (strtolower($v) == $str) return $k;
return false;
}
----
Server IP: 212.199.163.191
Probable Submitter: 89.1.83.53
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/80447
Del: integrated -- https://master.php.net/note/delete/80447/integrated
Del: useless -- https://master.php.net/note/delete/80447/useless
Del: bad code -- https://master.php.net/note/delete/80447/bad+code
Del: spam -- https://master.php.net/note/delete/80447/spam
Del: non-english -- https://master.php.net/note/delete/80447/non-english
Del: in docs -- https://master.php.net/note/delete/80447/in+docs
Del: other reasons-- https://master.php.net/note/delete/80447
Reject -- https://master.php.net/note/reject/80447
Search -- https://master.php.net/manage/user-notes.php