RE: [PHP] Comparison Operator

From: Date: Mon, 10 Jan 2005 21:19:48 +0000
Subject: RE: [PHP] Comparison Operator
Groups: php.general 
Request: Send a blank email to php-general+get-206022@lists.php.net to get a copy of this message
The function this is from sometimes uses $_POST or $_GET input, so sometimes its comparing 1337 with '1337' and === would break that. so I'll have to use something like: if (($value == $curval) && !(is_string ($curval) && ($value == 0))) unless there is a better way ________________________________ From: Brad Pauly [mailto:bpauly@gmail.com] Sent: Mon 2005-01-10 11:41 To: Chadwick, Russell Cc: php-general@lists.php.net Subject: Re: [PHP] Comparison Operator On Mon, 10 Jan 2005 10:26:16 -0800, Chadwick, Russell <Russell.Chadwick@infrastructuredev.com> wrote: > > Could anyone tell me why this code echos? > > <?php > $value = 0; > $curval = 'A'; > if ($value == $curval) { > echo "WTH, Over<br>"; > } > ?> The string is converted to an integer when compared with an integer. See this link for more info. http://us3.php.net/manual/en/language.operators.comparison.php Try using === instead. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#206022) next »