hostfreak Posted September 10, 2006 Share Posted September 10, 2006 I see it used often, e.g:[code]if (!isset($variable) { ...[/code]But, I am not sure of a practical use for it? I have been wondering for awhile now, it is really starting to bug me. Any answers are appreciated, thanks. Link to comment https://forums.phpfreaks.com/topic/20268-question-about-the-not-operator/ Share on other sites More sharing options...
btherl Posted September 10, 2006 Share Posted September 10, 2006 If you did[code]if (isset($variable))[/code]Then you would be checking if $variable is set.[code]if (!isset($variable))[/code]checks if $variable is NOT set. Basically, it gives you the opposite result to what you would normally get. Another example:[code]if ($var > 5) { print "$var is greater than 5\n";}if (!($var > 5)) { print "$var is NOT greater than 5\n";}[/code]The second is the exact opposite of the first. Link to comment https://forums.phpfreaks.com/topic/20268-question-about-the-not-operator/#findComment-89201 Share on other sites More sharing options...
kenrbnsn Posted September 10, 2006 Share Posted September 10, 2006 Most of the time I use this when I use the same script to process a form and to display it. In the form my submit button is usually named "thesubmitbutton" or something like that. This comes to my script in the $_POST array and is only defined when then form is submitted, so I can do something like:[code]<?phpif (isset($_POST['thesubmitbutton'])) {//// process form//} else {//// display form//}?>[/code]Another example would be storing a session variable, but only if it's not already set.[code]<?phpsession_start();if (!isset($_SESSION['my_var'])) $_SESSION['my_var'] = 'some value here';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/20268-question-about-the-not-operator/#findComment-89203 Share on other sites More sharing options...
hostfreak Posted September 10, 2006 Author Share Posted September 10, 2006 Ah, makes perfect sense now. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/20268-question-about-the-not-operator/#findComment-89204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.