note 26434 deleted from function.array-key-exists by philip
| From: | philip@php.net | Date: | Fri, 06 Dec 2002 17:21:49 +0000 |
| Subject: | note 26434 deleted from function.array-key-exists by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40432@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";}