Jump to content

Quick Question!


MaskedPhantom00

Recommended Posts

The following is explaining exactly what your asking... However generally the ! is used within logic, e.g. an 'if' statement, making it slightly different, but the same...

 

 

isset checks if the variable exists within the php session variable table, returning true if there (and is set to something other than NULL), false if not.

The ! technically inverts what ever follows it next (***)

 

In the second example the ! inverts what ever follows as before, but depending on what is in the specific post variable you may not get expected results. e.g. (can't find reference to ! in manual, so what follows will either be right, or will be the opposite... lol), if it contains a non empty string then it would be classed as true (I think) and then get inverted, however if the variable is say not set, null, or set as false or 0, then it will be computed to true.

 

 

 

If you were to use within an 'if' statement, the first statement would read: if the variable is not set then...

and the second statement would read: if the boolean representation of the variable is not true then...

 

 

 

That was a mind bender... so easy to think it, but to explain...lol

Link to comment
Share on other sites

The following is explaining exactly what your asking... However generally the ! is used within logic, e.g. an 'if' statement, making it slightly different, but the same...

 

 

isset checks if the variable exists within the php session variable table, returning true if there (and is set to something other than NULL), false if not.

The ! technically inverts what ever follows it next (***)

 

In the second example the ! inverts what ever follows as before, but depending on what is in the specific post variable you may not get expected results. e.g. (can't find reference to ! in manual, so what follows will either be right, or will be the opposite... lol), if it contains a non empty string then it would be classed as true (I think) and then get inverted, however if the variable is say not set, null, or set as false or 0, then it will be computed to true.

 

 

 

If you were to use within an 'if' statement, the first statement would read: if the variable is not set then...

and the second statement would read: if the boolean representation of the variable is not true then...

 

 

 

That was a mind bender... so easy to think it, but to explain...lol

 

Lol. You kind of explained a concept I already sort of understood. I read a book on Javascript and C++, so I have the idea behind the '!' statement. Maybe if I provide a bigger snippet of the code it would help to visualize my problem:

 

 

foreach ( $requiredFields as $requiredField ) {

    if ( !isset( $_POST[$requiredField] ) or !$_POST[$requiredField] ) {

      $missingFields[] = $requiredField;

    }

  }

 

I'm just having a difficult time visualizing the difference between the two variables. Like, when using !isset($_POST($requiredField)), my guess would be that if the variable is not 'set', meaning 'not initialized', it would set $missingFields[] = $requiredField.

 

 

Now the second portion of the if the statement is confusing me. I understand the 'or' part, seeing as how C++ and Javascript both carry the same idea, but the $_POST[$requiredField] part.  Does it mean if it was ever changed? or if anything was sent?

 

Maybe you may be able to assist me with this, seeing as how you may( I know you do) have more experience with interpreted languages than I do.

Link to comment
Share on other sites

Perhaps check into empty()

 

foreach ( $requiredFields as $requiredField ) {
    if ( empty( $_POST[$requiredField] )) {
      $missingFields[] = $requiredField;
    }
  }

 

However, if the strict error reporting is on, you may still get an undefined variable message - those you need to suppress or hide on a production environment.

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.