note 37784 deleted from function.array-search by felipe
| From: | felipe@php.net | Date: | Sun, 10 Feb 2008 13:11:14 +0000 |
| Subject: | note 37784 deleted from function.array-search by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135964@lists.php.net to get a copy of this message | ||
Note Submitter: mjwilco at yahoo dot com
----
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
?>