note 61768 modified in function.array-search by danbrown

From: Date: Wed, 29 Apr 2009 13:01:50 +0000
Subject: note 61768 modified in function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153986@lists.php.net to get a copy of this message
If you're searching for strings and you need a case-insensetive script, there's one: <?php function array_lsearch($str,$array){ $found=array(); foreach($array as $k=>$v){ if(strtolower($v)==strtolower($str)){ $found[]=$v; } } $f=count($found); if($f===0)return false;elseif($f===1)return $found[0];else return $found; } ?> It returns the original string, not the lower. Also good if use strtoupper(). --was-- If you're searching for strings and you need a case-insensetive script, there's one: function array_lsearch($str,$array){ $found=array(); foreach($array as $k=>$v){ if(strtolower($v)==strtolower($str)){ $found[]=$v; } } $f=count($found); if($f===0)return false;elseif($f===1)return $found[0];else return $found; } It returns the original string, not the lower. Also good if use strtoupper(). http://php.net/manual/en/function.array-search.php

« previous php.notes (#153986) next »