note 96533 modified in function.array-search by danbrown

From: Date: Thu, 04 Mar 2010 18:04:29 +0000
Subject: note 96533 modified in function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166671@lists.php.net to get a copy of this message
I needed a case insensitive array search function for a project... <?php /** * Performs the same function as array_search except that it is case * insensitive * @param mixed $needle * @param array $haystack * @return mixed */ function array_nsearch($needle, array $haystack) { $it = new IteratorIterator(new ArrayIterator($haystack)); foreach($it as $key => $val) { if(strcasecmp($val,$needle) === 0) { return $key; } } return false; } ?> --was-- I needed a case insensitive array search function for a project... <?php /** * Performs the same function as array_search except that it is case * insensitive * @param mixed $needle * @param array $haystack * @return mixed */ function array_nsearch($needle, array $haystack) { $it = new IteratorIterator(new ArrayIterator($haystack)); foreach($it as $key => $val) { if(strncmp($val,$needle) === 0) { return $key; } } return false; } ?> http://php.net/manual/en/function.array-search.php

« previous php.notes (#166671) next »