davelearning Posted February 8, 2011 Share Posted February 8, 2011 This may sound a bit stupid, but I cant get an if statement to work! I can get it to run if the answer is a number, eg if($variable=="1") { } but what if its a word? eg if($variable=="hello world") { } I cant get this to work! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/ Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 Are they the same including spelling, capitalization, and white space? 'Hello World' does not equal 'Hello world', or 'Hello World ' . . . Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171580 Share on other sites More sharing options...
fortnox007 Posted February 8, 2011 Share Posted February 8, 2011 if it's an integer i am pretty sure you don't need those " " around it either. if ($x == 1) { echo 'x is 1'; } Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171582 Share on other sites More sharing options...
davelearning Posted February 8, 2011 Author Share Posted February 8, 2011 Thanks for the replies Are they the same including spelling, capitalization, and white space? 'Hello World' does not equal 'Hello world', or 'Hello World ' . . . Yup exactly the same if it's an integer i am pretty sure you don't need those " " around it either. if ($x == 1) { echo 'x is 1'; } I wasnt sure, it works with them in! Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171587 Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 They can't be the same. What does var_dump($variable); return? As far as quoting numbers, a number can also be a string. When using the == comparison, PHP's type-juggling will show 10 and "10" to be the same. If you compare them with the identical comparison === operator, it will not. $str = '10' if( $str == 10 ) { // returns TRUE if( $str === 10 ) { returns FALSE Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171589 Share on other sites More sharing options...
davelearning Posted February 8, 2011 Author Share Posted February 8, 2011 ehhm, they are the same and it does work... The insert query I had the created $variable contained the error I should have just echoed out my variable Dunce hat on head.... Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171592 Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 D'oh! Quote Link to comment https://forums.phpfreaks.com/topic/227099-if-help/#findComment-1171593 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.