note 90245 deleted from language.types.array by danbrown
| From: | danbrown@php.net | Date: | Sun, 12 Apr 2009 03:31:21 +0000 |
| Subject: | note 90245 deleted from language.types.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153106@lists.php.net to get a copy of this message | ||
Note Submitter: strata_ranger at hotmail dot com
----
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';
?>