note 104727 added to function.array-key-exists

From: Date: Mon, 04 Jul 2011 07:14:41 +0000
Subject: note 104727 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-181214@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 222.166.181.161 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/104727 Del: integrated -- https://master.php.net/note/delete/104727/integrated Del: useless -- https://master.php.net/note/delete/104727/useless Del: bad code -- https://master.php.net/note/delete/104727/bad+code Del: spam -- https://master.php.net/note/delete/104727/spam Del: non-english -- https://master.php.net/note/delete/104727/non-english Del: in docs -- https://master.php.net/note/delete/104727/in+docs Del: other reasons-- https://master.php.net/note/delete/104727 Reject -- https://master.php.net/note/reject/104727 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181214) next »