note 88950 rejected from language.types.string by danbrown

From: Date: Sat, 14 Feb 2009 21:54:54 +0000
Subject: note 88950 rejected from language.types.string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150685@lists.php.net to get a copy of this message
Note Submitter: alan at allgo dot com ---- This is an interesting scenario: If I pass: $var1 = 0; if($var1=="some_string") { echo "this returns true only for 0"; } How can it return true when comparing an integer of 0 to any string? My guess is that its reading 0 as false and seeing the string as a "false" integer: hence, false == false. Am I right? The solution is to convert the integer to a string; $var1 = 0; $var1 = (string) $var1; if($var1=="some_string") { echo "this returns false"; }

« previous php.notes (#150685) next »