RE: [PHP] Variable Strangeness

From: Date: Wed, 21 Feb 2001 16:37:28 +0000
Subject: RE: [PHP] Variable Strangeness
Groups: php.general 
Request: Send a blank email to php-general+get-40992@lists.php.net to get a copy of this message
> I came across this: > $confidential = 0; > echo "$confidential " . ($confidential == "yes"); > In which "0 1" was printed. > Is there something I'm missing? Yes. When comparing types, PHP generally typcasts one side of the operand to the type of what is on the other side. So in the above operation, it is typecasting "yes" to an integer and so becomes a '0' (zero). Because of that, 0 == 0 and so resolves true. What you want to do is echo "$confidential " . ("$confidential" == "yes"); and you'll get your expected results. Chris

« previous php.general (#40992) next »