sgtbash Posted April 30, 2007 Share Posted April 30, 2007 ??? What does this do? Ive searched high and low over the internet for the purpose of the explanation mark before the variable and not found a thing, can someone help! if(!$variable){ Link to comment https://forums.phpfreaks.com/topic/49338-solved-ifvariable/ Share on other sites More sharing options...
obsidian Posted April 30, 2007 Share Posted April 30, 2007 Check the PHP Comparison Operators in the manual. With that read, it will make more sense. Basically, an if statement evaluates the clause to true or false. Throwing the '!' on the front practically switches the outcome of the statement. So, in that case, you are checking to see that the $variable evaluates to false. If so, then the statement is executed. Link to comment https://forums.phpfreaks.com/topic/49338-solved-ifvariable/#findComment-241767 Share on other sites More sharing options...
The Little Guy Posted April 30, 2007 Share Posted April 30, 2007 $variable = TRUE; if(!$variable){ }else{ } In the above example the else would be exicuted because $variable is set to TRUE and the ! means NOT, so it is saying: if $variable is NOT TRUE do this Link to comment https://forums.phpfreaks.com/topic/49338-solved-ifvariable/#findComment-241770 Share on other sites More sharing options...
sgtbash Posted May 2, 2007 Author Share Posted May 2, 2007 AHAR!!!! Thanks I figured it was something to do with NOT as i use the if(* != *) function all the time but was unaware you could use it to check it that quickly. Thanks Dan Link to comment https://forums.phpfreaks.com/topic/49338-solved-ifvariable/#findComment-243566 Share on other sites More sharing options...
obsidian Posted May 2, 2007 Share Posted May 2, 2007 AHAR!!!! Thanks I figured it was something to do with NOT as i use the if(* != *) function all the time but was unaware you could use it to check it that quickly. Thanks Dan You can use it to invert almost any phrase, too, which can get confusing rather quickly: <?php function returnFalse() { return FALSE; } if (!(returnFalse() !== FALSE)) // Evaluates to TRUE every time { } ?> Link to comment https://forums.phpfreaks.com/topic/49338-solved-ifvariable/#findComment-243604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.