NYCPHP Meetup

NYPHP.org

[nycphp-talk] Is @$arr['key'] ok?

Daniel Convissor danielc at analysisandsolutions.com
Mon Mar 10 13:27:37 EDT 2008


On Mon, Mar 10, 2008 at 09:28:29AM -0400, Kenneth Downs wrote:
> 
> function arraySafe($array,$key,$default='') {
>  if(isset($array[$key]))
>     return $array[$key];
>  else
>     return $default;
> }

Though this does get tripped up by $array[$key] being NULL.  
array_key_exists() is more accurate.

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list