Re: Array Question
| From: | Robert Cummings | Date: | Wed, 11 Jul 2007 15:02:08 +0000 |
| Subject: | Re: Array Question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258622@lists.php.net to get a copy of this message | ||
On Wed, 2007-07-11 at 15:52 +0100, Stut wrote:
> Robert Cummings wrote:
> > On Wed, 2007-07-11 at 09:46 +0100, Robin Vickery wrote:
> >> On 11/07/07, kvigor <k3cheese@insightbb.com> 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); }
> >
> > You can reduce the above statement to the following:
> >
> > $needle = (array)$needle;
> >
> > Conversion to array creates an array with one element... the value
> > converted.
>
> Without raising a notice?
Yep.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................