note 96553 added to function.array-search
| From: | camden dot michael at gmail dot com | Date: | Thu, 04 Mar 2010 17:56:10 +0000 |
| Subject: | note 96553 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166668@lists.php.net to get a copy of this message | ||
Whoops, meant to use strcasecmp...
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;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 70.99.89.86
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/96553
Del: integrated -- https://master.php.net/note/delete/96553/integrated
Del: useless -- https://master.php.net/note/delete/96553/useless
Del: bad code -- https://master.php.net/note/delete/96553/bad+code
Del: spam -- https://master.php.net/note/delete/96553/spam
Del: non-english -- https://master.php.net/note/delete/96553/non-english
Del: in docs -- https://master.php.net/note/delete/96553/in+docs
Del: other reasons-- https://master.php.net/note/delete/96553
Reject -- https://master.php.net/note/reject/96553
Search -- https://master.php.net/manage/user-notes.php