Re: = 0 and = "0"

From: Date: Thu, 25 Oct 2001 08:44:05 +0000
Subject: Re: = 0 and = "0"
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-72215@lists.php.net to get a copy of this message
> If you set $qty=0; then $qty has no value. Of course it has a value. The value is 0. Quite distinct from not having a value, or in proper terms, not being set. Try this: var_dump($qty); $qty = 0; var_dump($qty); Well, I will save you the trouble, it outputs: NULL int(0) > Type casting is irrelevant in php. No they aren't. Try this: $qty = 0; if($qty=="test") echo "foo"; if((string)$qty=="test") echo "bar"; This will only output "foo". Not "bar". You could also use the === operator to force PHP to check not only the value but also the type. See http://www.php.net/manual/en/language.operators.comparison.php -Rasmus

« previous php.general (#72215) next »