Paul Posted June 23, 2011 Share Posted June 23, 2011 Please would you guys clarify something for me. If a variable is set to FALSE, i.e. $test = FALSE, that doesn't mean the word false does it? It means FALSE as in the opposite to TRUE. Now if you do: if($test) {and so on... This will not pass the 'if' test as the variable is set to FALSE. What if it's set to TRUE? I'm not clear on the FALSE, TRUE bit of variables. Thanks Paul Link to comment Share on other sites More sharing options...
Jonathon Posted June 23, 2011 Share Posted June 23, 2011 Yes your basically correct. $test = FALSE; // the variable is 'not true' in a sense. This would fail an if ($test) statement $test = 'false' // would be the word 'false' if $test = true; if ($test) { // then the variable test exists and the if statement is satisfied meaning you can run your code // Do something here } Hope that clears it up for you 1 Link to comment Share on other sites More sharing options...
HartleySan Posted June 24, 2011 Share Posted June 24, 2011 FALSE and TRUE can also be false and true. They're not case sensitive. Link to comment Share on other sites More sharing options...
Jonathon Posted June 24, 2011 Share Posted June 24, 2011 Yep. Mine are always lower case. Link to comment Share on other sites More sharing options...
Paul Posted June 24, 2011 Author Share Posted June 24, 2011 Thanks gents. So the statement if ($test) just tests that a variable exists? But what, for a variable, does 'exist' mean. NULL, TRUE, FALSE, number or text? What's it's default 'value'. Is it NULL? If you're wondering why I'm banging on about this I'm on script 16.6, lines 16 and 50. I understand what line 16 does, but does it have to be FALSE, could it just as well be NULL? Link to comment Share on other sites More sharing options...
Larry Posted June 24, 2011 Share Posted June 24, 2011 No, that conditional will only be true if $test has a "true" value, meaning it exists and isn't equal to false or an empty string or 0 or NULL. If you want to test for a variable's existence, you'd use isset(). Variables do not have default values in PHP. As for Script 16.6, without looking at the script, I'm fairly sure it would also work if you set the variable equal to NULL. Link to comment Share on other sites More sharing options...
Recommended Posts