shane18 Posted September 20, 2009 Share Posted September 20, 2009 I always wondered why //CODE START $user_id = $account_lookup[0]; //Value is 1 $BLAH2 = 1; if($BLAH2 == 1){ //CODE END comes out to be false ..... then i figured out $USER_ID is a string... and $BLAH2 is a int..... so my question is... 1. Do VAR TYPES matter in if statements all the time... Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/ Share on other sites More sharing options...
trq Posted September 20, 2009 Share Posted September 20, 2009 PHP is smart enough (or stupid enough depending on how you look at it) to accept that '10' is the same as 10. Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921520 Share on other sites More sharing options...
shane18 Posted September 20, 2009 Author Share Posted September 20, 2009 then why does $USER_ID2 = 1; if($USER_ID2 == "1"){ come out as false... then when i do $USER_ID2 = "1"; if($USER_ID2 == "1"){ it comes out as true test it and see what happens.. Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921526 Share on other sites More sharing options...
trq Posted September 20, 2009 Share Posted September 20, 2009 #!/usr/bin/php <?php $a = '10'; echo $a == '10' ? "true\n" : "false\n"; echo $a == 10 ? "true\n" : "false\n"; Results in.... true true Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921530 Share on other sites More sharing options...
shane18 Posted September 20, 2009 Author Share Posted September 20, 2009 can it be my version of PHP its 4.3.11, and also my results for the $USER_ID come from a mysql_fetch_row function. Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921531 Share on other sites More sharing options...
corbin Posted September 20, 2009 Share Posted September 20, 2009 if($USER_ID2 === "1") Would be false. but if($USER_ID2 == "1") wouldn't be false in any version of PHP. Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921533 Share on other sites More sharing options...
shane18 Posted September 20, 2009 Author Share Posted September 20, 2009 thanks a lot, I been using !== and dealed with the issue.. wow.... lol thanks a lot for helping my... spacin self Link to comment https://forums.phpfreaks.com/topic/174862-solved-var-type-question/#findComment-921537 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.