SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: !== operator

  1. #1
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    !== operator

    What is the !== or === (i guess) operator all about?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It's used to check whether or not two values are identical (if both the value and the datatype is the same).

    PHP Code:
    if( == false ) echo 'this will be printed';
    if( 
    === false ) echo 'this will not...'
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    === is identity
    !== is nonidentity

    compares the value of the variable(s) and type of the value of the variable(s) in an expression

    identity returns true on match and false on mismatch
    non-identity returns true on mismatch and false on match

    regards,

    melan'

  4. #4
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks

  5. #5
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a difference between != and !==? = and == does, but I don't see how != can mean "if it doesn't assign" logic.

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Atealtha
    Is there a difference between != and !==? = and == does, but I don't see how != can mean "if it doesn't assign" logic.
    There's a huge difference between != and !==. You have to remember that != and == are in the same field, and !== and === are in the same field. The = and == comparison is a different story all together. = is an assignment operator, != and !== are both comparison operators just like == and ===.

    PHP Code:
       <?php
       $a 
    5// Assignment operator.
       
    if ($a == 5)
       {
           echo 
    'We WILL get here.';
       }
       if (
    $a === 5)
       {
           echo 
    'We will also get here';
       }
       if (
    $a === '5')
       {
          echo 
    'We will NOT get here.';
       }
       if (
    $a !== 3)
       {
          echo 
    'WILL get here';
       }
       if (
    $a !== '5')
       {
           echo 
    'Will get here.';
       }
       if (
    $a != '5')
       {
         echo 
    'Will NOT get here.';
       }
      if (
    $a 3)
      {
     echo 
    'This will always return true, as this was an ASSIGNMENT operator. This if statemen just overwrote $a to be 3 instead of 5, and the assignment ends up returning true.';
      }

  7. #7
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    just to give a flat definition for the operators:

    === called the identity operator
    checks both value AND dataType of value when doing a comparison returns true on match

    !== called the nonIdentity operator
    checks both value AND dataType of value when doing a comparison returns true on mismatch

    == is called the Equality operator
    checks values (only) when doing a comparison returns true on match

    != is called the Inequality operator
    checks values (only) when doing a comparison returns true on mismatch

    <> (also) called inequality operator
    checks values (only) when doing a comparison returns true on mismatch

    regards,

    'cholic

  8. #8
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It compares variables. It is the same as != and ==, except it also checks if they are the same type of variable.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  9. #9
    SitePoint Zealot karnetics's Avatar
    Join Date
    Dec 2004
    Location
    USA
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this piece of code!!!

    PHP Code:
    <?php
       
       
    switch ($a 5)// Assignment operator.
       
    {
            case 
    1;
            
    $a == 5;
               echo 
    'We WILL get here.';
               break;

            case 
    2;
               
    $a === 5;
               echo 
    'We will also get here';
               break;
               
               
            case 
    3;
             
    $a === '5';
            echo 
    'We will NOT get here.';
            break;
       
    //repeated steps until the end of your code
       
    }
    echo 
    'This will always return true, as this was an ASSIGNMENT operator. This if statemen just overwrote $a to be 3 instead of 5, and the assignment ends up returning true.';

      
    ?>


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
  •