note 85749 added to function.in-array
| From: | james dot randell at hotmail dot co dot uk | Date: | Tue, 16 Sep 2008 09:54:54 +0000 |
| Subject: | note 85749 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144440@lists.php.net to get a copy of this message | ||
Small method i built for my Array module, after looking through the manual I wanted a small compact
way of making a wildcard search through an arrays values, and returning only those that it found.
<?
/**
* Takes a needle and haystack (just like in_array()) and does a wildcard search on it's
values.
*
* @param string $string Needle to find
* @param array $array Haystack to look through
* @result array Returns the elements that the $string was found in
*/
function find ($string, $array = array ())
{
foreach ($array as $key => $value) {
unset ($array[$key]);
if (strpos($value, $string) !== false) {
$array[$key] = $value;
}
}
return $array;
}
?>
----
Server IP: 92.48.100.16
Probable Submitter: 194.6.79.200
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/85749
Del: integrated -- https://master.php.net/note/delete/85749/integrated
Del: useless -- https://master.php.net/note/delete/85749/useless
Del: bad code -- https://master.php.net/note/delete/85749/bad+code
Del: spam -- https://master.php.net/note/delete/85749/spam
Del: non-english -- https://master.php.net/note/delete/85749/non-english
Del: in docs -- https://master.php.net/note/delete/85749/in+docs
Del: other reasons-- https://master.php.net/note/delete/85749
Reject -- https://master.php.net/note/reject/85749
Search -- https://master.php.net/manage/user-notes.php