SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: === ??

  1. #1
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    === ??

    Ok, I know what:

    = is

    and I know what

    == is

    but what in the world is:


    ===



    ???


    ie


    if ($foo === $bar) {




    Thanks.
    John B. Abela
    www.JohnAbela.Com

  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)
    i believe it's equivalent to == (the logically equal-to)
    Defender's Designs
    I'm Getting Married!

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

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/manual/en/languag...comparison.php

    it compares the equality and type (PHP 4 only).

    run this:

    PHP Code:
    $a 0;
    $b '0';

    if (
    $a == $b)  { echo "They're equal.<br />"; }
    if (
    $a !== $b) { echo "They're not equal."; } 
    output:

    They're equal.
    They're not equal.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In loosely-typed languages such as PHP and Perl, the interpreter will cast a value to the required type according to the context of its use. So we often don't think about what type our variables have because it is mainly irrelevent to how we code. But the underlying type is there (int, string, double, float, null, etc).

    In Dr Peper's example $a will have a type of int or real (not sure - I would have to check the manual ) and $b would have a type of string.

    There may be times when we need to deal more strictly with a variable's type in our code. We may need to check for a variable's type. Thus the functions is_null(), is_int(), etc. Which help us determine the type of a variable.

    As Dr Pepper has already suggested, we can also test for equalitly of value AND type using the === and !== operators.

  5. #5
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, Thanks guys!


    I finally understand




    Checking for type, that is ingenious!




    Again, thanks!
    John B. Abela
    www.JohnAbela.Com


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
  •