RE: in_array - what the...

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

 



> -----Original Message-----
> From: Gary . [mailto:php-general@xxxxxxxxxxxxxxx]
> Sent: 25 June 2010 08:18
> To: PHP
> Subject:  in_array - what the...
> 
> 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.

To do what you want to do, simply do an isset():

  if (isset($array['mac_address'])):
    // do stuff with $array['mac_address']
  else:
    // it doesn't exist
  endif;


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.ford@xxxxxxxxxxxxxx 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
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