note 96533 modified in function.array-search by danbrown

From: Date: Wed, 03 Mar 2010 19:08:28 +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-166635@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(strncmp($val,$needle) === 0) { return $key; } } return false; } ?> --was-- I needed a case insensitive array search function for a project... /** * 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 (#166635) next »