Jump to content

Question about the "Not" Operator


hostfreak

Recommended Posts

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
Share on other sites

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]<?php
if (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]<?php
session_start();
if (!isset($_SESSION['my_var'])) $_SESSION['my_var'] = 'some value here';
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.