note 80447 deleted from function.array-search by danbrown

From: Date: Wed, 29 Apr 2009 12:55:28 +0000
Subject: note 80447 deleted from function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153969@lists.php.net to get a copy of this message
Note Submitter: phpawe at aweawe dot cjb dot net ---- 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; }

« previous php.notes (#153969) next »