kamal_sahoo Posted October 20, 2005 Share Posted October 20, 2005 When I use 0=='Somevalue' it returns true. Is this a PHP bug? For example : <? if(0=='Unlimited') echo "Yes unlimited"; It prints "Yes Unlimited"; ?> Link to comment Share on other sites More sharing options...
Guest Posted October 20, 2005 Share Posted October 20, 2005 Why should that be a bug? Matti Link to comment Share on other sites More sharing options...
Guest Posted October 20, 2005 Share Posted October 20, 2005 from php.net If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. And for the conversion: The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Link to comment Share on other sites More sharing options...
kamal_sahoo Posted October 21, 2005 Author Share Posted October 21, 2005 Thanks, Mark. Yes you are right. When integer compares with string the string first converts to integer and then comparasion takes place. But how is it possible : 'Somevalue'==0 returns true. It compares string to integer. Don't you think first integer converts to string and then comparasion takes place. thanks in advance. Link to comment Share on other sites More sharing options...
Guest Posted October 21, 2005 Share Posted October 21, 2005 'Somevalue'==0 returns true. no, because see what it says: If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). so 'somevalue' is first coverted to 0. Link to comment Share on other sites More sharing options...
kamal_sahoo Posted October 22, 2005 Author Share Posted October 22, 2005 Ok, That's great. Thank you very much. Link to comment Share on other sites More sharing options...
Harald Ponce de Leon Posted November 12, 2005 Share Posted November 12, 2005 You might want to use the following instead: 'somevalue' === 0 The === makes an additional check to see if both values are of the same type. , osCommerce Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.