note 37784 added to function.array-search

From: Date: Thu, 27 Nov 2003 01:42:59 +0000
Subject: note 37784 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-61012@lists.php.net to get a copy of this message
array_search() must match the whole value, not just a portion. To search for a portion, use: <?php $myarray = array("some apples", "some bannanas", "some oranges"); function array_search_bit($search, $array_in) { foreach ($array_in as $key => $value) { if (strpos($value, $search) !== FALSE) return $key; } return FALSE; } $searchkey = array_search("oranges", $myarray); //old function, returns FALSE $searchkey = array_search_bit("oranges", $myarray); //new function, returns 2 ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37784 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37784&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37784&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61012) next »