Re: Weird comparison error.

From: Date: Sat, 28 Jun 2003 18:28:00 +0000
Subject: Re: Weird comparison error.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-153275@lists.php.net to get a copy of this message
In PHP there are two operators for comparisons, the double and triple equivalance. Double equivalance just check's the boolean type so if (0 == 'n') is translated to if (False == False), where as triple equivalance checks the data types as well so if (0==='n') becomes if (Int(False)==String(False)) but since the data types don't match that would be False. to get a better reference check PHP.net for 'Bolean Types' , because I think I dodn't explain the double equivalance right, and also it will clarify situations of the Null type. Bobby "Rob Adams" <rob_adams@hotmail.com> wrote in message news:20030627212435.84480.qmail@pb1.pair.com... > I don't need anything fixed, I'm just curious about something I noticed. > > I'm doing a comparison between a variable and a hard coded char. Like this: > if ($k1 == "n") > > The variable is usually the first key in an array (0) so it should usually > evaluate false, but it was true every time until I changed it to: > if ($k1 === "n") > > So I'm assuming that it decided that since $k1 was an int to convert "n" to > an int (which would be 0) and conclude that 0 does indeed equal "n". So I > decided for fun to try: > if ("n" == $k1) > > And it still was true everytime. So why does it always try convert my > literal to an int instead of use the variable as a string? > > Just curious. Thanks. > > -- Rob > >

« previous php.general (#153275) next »