Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between =, == and === in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.77k
    Comment on it

    In PHP programming, Many times we have seen and used different operators of PHP. This article demonstrate the difference between the operators which looks identical but used for different operations. In PHP we have three types of equal sign (=) operators, The description of each type is given below :

    1. = : "=" stands for assignment operator. This operator is used for assigning values to variables.

    Example :

    <?php
    $var = 'Test';
    ?>
    

    2. == : "==" stands for equality operator. This operator used to check the value of operands are equal or not.

    Example :

    <?php
    $x = '7';
    $y = 7;
    if($x == $y)
    {
     echo "Equal";
    }
    else
    {
     echo "Not Equal";
    }
    ?>
    

    Output : Equal

    3. '===' : "===" stands for identical operator. This operator checks the values as well as the type of operands are same or not.

    <?php
    $x='7';
    $y=7
    if($x === $y){
      echo "Equal";
    }else{
      echo "Not Equal";
    }
    echo "<br-->";
    if($x === string($y)){
       echo "Equal";
    }else{
       echo "Not Equal";
    }
    ?>
    

    Output :

    Not Equal

    Equal


    Note : '==(equal)' operator performs typecasting automatically to compare values of operand while '===(identical)' operator performs typesafe comparison.


 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: