RE: [PHP] in_array - what the...
| From: | Daevid Vincent | Date: | Fri, 25 Jun 2010 17:35:16 +0000 |
| Subject: | RE: [PHP] in_array - what the... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306436@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Gary . [mailto:php-general@garydjones.name]
> Sent: Friday, June 25, 2010 1:14 AM
> To: PHP
> Subject: Re: [PHP] in_array - what the...
>
> "Ford, Mike" writes:
> >> -----Original Message-----
> >> If I have an array that looks like
> >> array(1) {
> >> ["mac_address"]=>
> >> string(2) "td"
> >> }
> >>
> >> and I call
> >> if (in_array($name, self::$aboveArray))
> >> with $name as
> >> string(11) "mac_address"
> >>
> >> what should be the result?
> >
> > FALSE -- in_array checks the *values*, not the keys, so would be
> > looking at the "td" for this element.
>
> Agh! So it does.
>
> You know what's worse? I even looked at the documentation of the
> function this morning wondering if that's what the problem was and
> *still* didn't see it!
>
> *slinks away in embarrassment*
Why do this "in_array()" business??
Just do this...
if (self::$aboveArray[$name])
{
//something interesting here
}