SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checking if a variable is set

    if you want to check if a variable is set, there are more ways you can go right?

    -if(IsSet($var))......
    -if($var).........
    -if($var!="NULL").........
    etc

    are they all the same or does it matter wichone you use?
    Last edited by =X=; Aug 2, 2001 at 14:40.

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there's also
    PHP Code:
    if (!$var
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing to keep in mind though is let's take this example.
    Try this example on your own server. You will see that since $foo is established in the script, even though it has no value, isset($foo) will evaluate true. if($foo) will not.


    PHP Code:
    <?
    $foo 
    "";
    ?>

    <?=(!$foo) ? '!$foo = true' '!$foo = false'?><br>
    <?=(!isset($foo)) ? '!isset($foo) = true' '!isset($foo) = false' ?><br>
    <?=($foo) ? '$foo = true' '$foo = false'?><br>
    <?=(isset($foo)) ? 'isset($foo) = true' 'isset($foo) = false' ?><br>
    <?=($foo != '') ? '$foo != \'\' = true' '$foo != \'\' = false'?><br>
    <?=($foo != NULL) ? '$foo != NULL = true' '$foo != NULL = false'?><br>
    <?=($foo == '') ? '$foo == \'\' = true' '$foo == \'\' = false'?><br>
    <?=($foo == NULL) ? '$foo == NULL = true' '$foo == NULL = false'?><br>
    Try
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh you've costed me 10 minutes time with that script

    damn sitepointforums never allow you to just copy/past
    I never seem to remember that )

    instead you have to copy/past, and replace all spaces with normal spaces...

    and there was a mistake in your script too, you need to add slashes on some places like:

    $foo != '' twice and
    $foo == '' twice

    But it works, and I learned a wise lesson-->never use isset

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    VB strips my \ I had them in there.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah ok


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •