Re[2]: [PHP] empty and isset
| From: | Tom Rogers | Date: | Fri, 07 Feb 2003 00:53:40 +0000 |
| Subject: | Re[2]: [PHP] empty and isset | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134699@lists.php.net to get a copy of this message | ||
Hi,
Friday, February 7, 2003, 4:39:42 AM, you wrote:
JW> On Friday 07 February 2003 01:35, Mike.Kent@indystar.com wrote:
>> Thanks for clearing that up.
JW> Hmm, it seems like you still haven't grasped it yet :)
>> So input of type text does a set, which makes
>> isset() true,
JW> Correct.
>> but isset() does not return true if $var is merely empty.
JW> Incorrect. Basically empty($var) returns TRUE if $var evaluates to FALSE, and
JW> in this context if $var is undefined it evaluates to FALSE. isset($var)
JW> returns TRUE if $var has been defined & is a non-NULL value, and returns
JW> FALSE if $var is undefined or is set to NULL.
JW> --
Jason Wong ->> Gremlins Associates -> www.gremlins.biz
JW> Open Source Software Systems Integrators
JW> * Web Design & Hosting * Internet & Intranet Applications Development *
JW> ------------------------------------------
JW> Search the list archives before you post
JW> http://marc.theaimsgroup.com/?l=php-general
JW> ------------------------------------------
JW> /*
JW> Conquering Russia should be done steppe by steppe.
JW> */
Here is a bit of code that will make it as clear as mud:
echo '<br>Start Test <br>';
for($x=1;$x<5;$x++){
if (isset($test)){
echo $x.' $test is set. <br>';
if(!empty($test)){
echo $x.' Not empty check returns not empty ('.$test.').
<br>';
}else{
echo $x.' Not empty check returns empty ('.$test.').
<br>';
}
if(empty($test)){
echo $x.' $test is empty ('.$test.'). <br>';
}else{
echo $x.' $test contains '.$test.'<br>';
}
}else{
echo $x.' $test is not set yet. <br>';
}
if($x == 1){
if(empty($test)){
echo $x.' Empty check returns empty. <br>';
}else{
echo $x.' Empty check returns not empty.
'.$test.'<br>';
}
if(!empty($test)){
echo $x.' Not empty check returns not empty. <br>';
}else{
echo $x.' Not empty check returns empty. <br>';
}
$test = '';
}
if($x == 2){
$test = 0;
}
if($x == 3){
$test = $x;
}
echo '<br>';
}
--
regards,
Tom