note 90245 added to language.types.array
| From: | strata_ranger at hotmail dot com | Date: | Sun, 12 Apr 2009 03:11:19 +0000 |
| Subject: | note 90245 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153105@lists.php.net to get a copy of this message | ||
Responding to genix at arctoz dot de, bear in mind that isset() returns FALSE if an array element
has been explicitly assigned NULL. In most cases this is not a problem, however if you do at some
point need to make a distinction between NULL and unset array elements you should use
array_key_exists() instead of isset().
<?php
$array = Array('foo' => null);
// Outputs 'Foo does not exist' because $array['foo'] is NULL
if (isset($array['foo'])) echo 'Foo exists'; else 'Foo does not
exist';
// Outputs 'Foo exists' ...because it does
if (array_key_exists($array, 'foo')) echo 'Foo exists'; else 'Foo does not
exist';
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.2.25.104
----
Manual Page -- http://www.php.net/manual/en/language.types.array.php
Edit -- https://master.php.net/note/edit/90245
Del: integrated -- https://master.php.net/note/delete/90245/integrated
Del: useless -- https://master.php.net/note/delete/90245/useless
Del: bad code -- https://master.php.net/note/delete/90245/bad+code
Del: spam -- https://master.php.net/note/delete/90245/spam
Del: non-english -- https://master.php.net/note/delete/90245/non-english
Del: in docs -- https://master.php.net/note/delete/90245/in+docs
Del: other reasons-- https://master.php.net/note/delete/90245
Reject -- https://master.php.net/note/reject/90245
Search -- https://master.php.net/manage/user-notes.php