|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-10-30 11:42 UTC] sander@php.net
[2001-10-30 14:09 UTC] raymond at bokenkamp dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 09:00:01 2025 UTC |
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";