note 104727 deleted from function.array-key-exists by danbrown

From: Date: Tue, 05 Jul 2011 13:44:02 +0000
Subject: note 104727 deleted from function.array-key-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181249@lists.php.net to get a copy of this message
Note Submitter: nik tang ---- Just a remind to everyone who wants to replacing array_key_exists() with isset() for performance as proposed by anonymous comment on 16-Jun-2011 : isset() wouldn't give you the same result as array_key_exists() so you may end up with hidden bugs/danger in your program. Example: $arr = array('a'=>1, 'b'=>2, 'c'=>null, 'd'=>'testing'); var_dump(isset($arr['c'])); //false. var_dump(array_key_exists('c', $arr)); //true. var_dump(isset($arr['d']['abc'])); //true!!!! var_dump(array_key_exists('abc', $arr['d'])); //warning Try google 'isset() + array' and you will find many discussion about this. Be careful.

« previous php.notes (#181249) next »