Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: php null values

  1. #1
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts

    php null values

    hi ,

    can i replace this line

    PHP Code:
    if($pluOnSite == "" or $pluOnSite == NULL or $pluOnSite == 0){} 

    WITH


    PHP Code:
    if($pluOnSite) {} 
    Please de-reputate me
    © 0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #2
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Simply put, no. It doesn't do the same thing, if you have what you have now then if the value does equal null or whatever it won't run the if statement, they are completely different statements.

  • #3
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Take a look at the comparison tables in the PHP appendix. I've found that using empty() is sufficient in most cases.

  • #4
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    That was my mistake i mean to say

    if(!$pluOnSIte)

    i think empty() is the best function. Thanks all
    Please de-reputate me
    © 0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, you're right in you're first post mate. PHP's weak datatypes allow you to treat all of these (source: http://ca3.php.net/manual/en/languag....boolean.php):
    • the boolean FALSE itself
    • the integer 0 (zero)
    • the float 0.0 (zero)
    • the empty string, and the string "0"
    • an array with zero elements
    • an object with zero member variables (PHP 4 only)
    • the special type NULL (including unset variables)
    • SimpleXML objects created from empty tags

    as a boolean false. These will all fail in an identical ( false === null) test, but will pass a comparison test with juggling.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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