note 85749 modified in function.in-array by danbrown
| From: | danbrown@php.net | Date: | Tue, 16 Sep 2008 15:24:44 +0000 |
| Subject: | note 85749 modified in function.in-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144449@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.
<?php
/**
* 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;
}
?>
--was--
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;
}
?>
http://php.net/manual/en/function.in-array.php