note 26434 added to function.array-key-exists

From: Date: Wed, 30 Oct 2002 17:18:31 +0000
Subject: note 26434 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-38761@lists.php.net to get a copy of this message
I got stuck trying to figure out the correct test on an array key/value. I wrote this to help me see the difference. I hope it helps someone save a few minutes. # Unremark one of these declarations to see the effect. # $qwerty=array(); # $qwerty["badge"]=null; # $qwerty["badge"]=""; # $qwerty["badge"]="test_data"; # Test if the array exists at all if (!isset($qwerty)) { print "<p>Failed isset on array \n";} # Test if the key exists in the array - doesn't check or care about a value yet if (!array_key_exists("badge",$qwerty)) { print "<p>Failed array_key_exists \n";} # Test if the key has been assigned a value during this run (could be "") if (!isset($qwerty["badge"])) { print "<p>Failed isset on array key value \n";} # Test if the key has a value of any sort (not true if "") if (!($qwerty["badge"])) { print "<p>Failed contents examination of array key value \n";} -- http://www.php.net/manual/en/function.array-key-exists.php http://master.php.net/manage/user-notes.php?action=edit+26434 http://master.php.net/manage/user-notes.php?action=delete+26434 http://master.php.net/manage/user-notes.php?action=reject+26434

« previous php.notes (#38761) next »