Re: Array Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks,

I've seen the light by your code.

""Robin Vickery"" <robinv@xxxxxxxxx> wrote in message 
news:5cb2dafd0707110146u6231416fm9afc5a9f3d5bf76b@xxxxxxxxxxxxxxxxx
> On 11/07/07, kvigor <k3cheese@xxxxxxxxxxxxx> wrote:
>> Is there a php function similar to in_array that can detect if a "partial
>> value" is in an array value or not:
>>
>> e.g.
>>
>> $var1 = " big horse";    $var2 = " small yellow";    $var3 = " red 
>> hydrant";
>>
>> $theArray = array(big blue horse, small yellow bird, giant red hydrant);
>>
>> Is there a way to find out if $var1 in $theArray or $var2 etc.?
>
> There's not a built in function, but it's not hard to write one:
>
> function partial_in_array($needle, $haystack) {
>  if (!is_array($needle)) { $needle = array($needle); }
>
>  $needle = array_map('preg_quote', $needle);
>
>  foreach ($needle as $pattern) {
>    if (count(preg_grep("/$pattern/", $haystack)) > 0) return true;
>  }
>
>  return false;
> } 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux