note 36110 added to function.array-search
| From: | zitan at mediasculpt dot net | Date: | Fri, 26 Sep 2003 01:51:27 +0000 |
| Subject: | note 36110 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57146@lists.php.net to get a copy of this message | ||
Just a quick note: array_search finds sub strings in your arrays values i.e "sports" in
"sports_template", which isn't always desirable. Here's a quick and dirty
direct match function to solve this that I find useful ::
<?
function array_search_match($needle, $haystack){
$rkey = NULL;
foreach($haystack as $key => $array){
foreach($array as $value){
if($value==$needle){
$rkey = $key;
}
}
}
return $rkey;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36110
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36110&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36110&report=yes