Re: Re: Fuzzy Array Search
| From: | Shawn McKenzie | Date: | Tue, 07 Jun 2011 21:37:25 +0000 |
| Subject: | Re: Re: Fuzzy Array Search | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313453@lists.php.net to get a copy of this message | ||
On 06/07/2011 04:28 PM, Floyd Resler wrote:
>
> Shawn,
> I'm terrible with regular expressions. Could you give me an example?
>
> Thanks!
> Floyd
>
>
Depends. Could be as simple as this to return an array of all
occurrences of $needle in any of the $haystack_array values:
$haystack_array = array('something is here', 'nothing matches here',
'there will be a somethingsomething match here');
$needle = 'something';
$matches_array = preg_grep("/$needle/", $haystack_array);
Depends on where you are getting the search criteria and how you want it
to match in the array. BTW... If this is originally in a database then
you can do it there with the LIKE operator and % wildcard.