Bug #13874 Updated: isset on a associative array does not distinct if key exist
| From: | raymond at bokenkamp dot com | Date: | Tue, 30 Oct 2001 19:09:59 +0000 |
| Subject: | Bug #13874 Updated: isset on a associative array does not distinct if key exist | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-69349@lists.php.net to get a copy of this message | ||
ID: 13874
User updated by: raymond@bokenkamp.com
Reported By: raymond@bokenkamp.com
Status: Bogus
Bug Type: Unknown/Other Function
Operating System: ALL
PHP Version: 4.0.6
New Comment:
understood. However there is still no effective way to check if a key exists in an array !!!
Maybe my title should have been different ... for the real problem see my sample ...
Previous Comments:
------------------------------------------------------------------------
[2001-10-30 11:42:42] sander@php.net
Not a bug. Intended behaviour. isset() returns false on variables with a NULL value.
Documentation is being worked on.
------------------------------------------------------------------------
[2001-10-30 11:23:43] raymond@bokenkamp.com
There's no good way to check weather a key exists in an associative array.
The problem is that if the key exists, but the value is null, is treated the
same as if the key doesn't exist.
The only way I figure is to check: in_array("key", array_keys($array))
but this seams rather expensive.
(Compare: perl has an "exists" function ...)
Sample:
$sample = array("a" => "a", "b" => NULL);
print ":".isset($sample['a'])."<br>\n";
print ":".isset($sample['b'])."<br>\n";
print ":".isset($sample['c'])."<br>\n";
print ":".in_array("a", array_keys($sample))."<br>\n";
print ":".in_array("b", array_keys($sample))."<br>\n";
print ":".in_array("c", array_keys($sample))."<br>\n";
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13874&edit=1