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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.