| 
	
 | 
 Posted by Geoff Berrow on 07/05/06 10:39 
Message-ID: <4h19smF1ldsruU1@individual.net> from Paul Lautman contained 
the following: 
 
>Could you explain your statement 
> 
>> can't do if( Astring == Bstring) must use strcmp() 
> 
>I often compare strings in an if statement?  
 
So do I.  It may be something to do with this: 
 
http://uk.php.net/strcmp 
 
From the user notes... 
 
When we make a comparison with == php automaticly converts strings to 
integers when either side of the comparison is an integer, f.e.: 
<? 
$value = 0; 
if($value == "submit") { 
   echo "Let's submit"; 
} 
?> 
Above would be succesful, since "submit" is converted to an integer (eq 
0) and the equation is would return true; (that's why (1 == "1submit") 
would also return true) 
 
That's why we should use strcmp or === (checks type also), for string 
comparisons. 
--  
Geoff Berrow (put thecat out to email) 
It's only Usenet, no one dies. 
My opinions, not the committee's, mine. 
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
 
  
Navigation:
[Reply to this message] 
 |