Re: wierd if statments

From: Date: Thu, 26 Oct 2000 21:54:15 +0000
Subject: Re: wierd if statments
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22216@lists.php.net to get a copy of this message
Chris Lee writes: > <? > $tmp1 = 0; > $tmp2 = "all"; > > if ($tmp1 == $tmp2) > echo "TRUE<br>\n"; > else > echo "FLASE<br>\n"; > ?> > > Whats going on here, this returns TRUE !!! > > Chris Lee Yup. Read the manual section on String Conversion, and the section on Type Juggling: http://www.php.net/manual/language.types.string.php#language.types.string.conversion http://www.php.net/manual/language.types.type-juggling.php Basically, for the purposes of this conversion, "all" is being evaluated as an integer, since you're comparing it directly with an integer. The integer conversion of "all" results in the value 0; therefore, the expression evaluates to TRUE. In PHP 4, use the '===' operator to do this comparison. It means 'identical to'; i.e., 'is equal and of the same type'. Hope this helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#22216) next »