RE: [PHP] Variable Strangeness

From: Date: Thu, 22 Feb 2001 11:14:38 +0000
Subject: RE: [PHP] Variable Strangeness
Groups: php.general 
Request: Send a blank email to php-general+get-41134@lists.php.net to get a copy of this message
you made a comparison in your code. it returned true which is 1. what are you trying to do anyway? if you want to compare and print it only if it's yes then do: $confidential = 0; echo "$confidential " . $confidential ? 'yes' : ''; Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) maxim@phpbeginner.com www.phpbeginner.com -----Original Message----- From: php3@developersdesk.com [mailto:php3@developersdesk.com] Sent: Thursday, February 22, 2001 1:56 AM To: Jason Murray; php-general@lists.php.net Subject: Re: [PHP] Variable Strangeness Addressed to: Jason Murray <jason@jwebmedia.com> php-general@lists.php.net ** Reply to note from Jason Murray <jason@jwebmedia.com> Wed, 21 Feb 2001 11:37:40 -0600 > > Hi, > > I came across this: > > $confidential = 0; > echo "$confidential " . ($confidential == "yes"); > > In which "0 1" was printed. > $confidential = 0; # Numeric 0 That explains the 0. $confidential == "yes" This is a little tricky. The numeric value of 'yes' is 0, so it evaluates to the same thing as 0 == 0, which is true. True has a numeric value of 1, although all values besides 0 are considered true. You might want to look at the === operator which checks that both the value and the type of the operands is identical. http://www.php.net/manual/en/html/language.operators.comparison.html Rick Widmer Internet Marketing Specialists http://www.developersdesk.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#41134) next »