What is the difference between = and ==?

后端 未结 4 1984
孤独总比滥情好
孤独总比滥情好 2020-12-03 19:52

What is the difference between = and ==? I have found cases where the double equal sign will allow my script to run while one equal sign produces a

4条回答
  •  时光取名叫无心
    2020-12-03 20:34

    • (=) is a Assignment operator while (==) is a Equal to operator.
    • (=) is used for assigning the values from right to left while (==) is used for showing equality between values.

    Example:

    $test = 1;
    if($test=2){
    echo "Hello";
    }
    
    if($test==2){
    echo "world";
    }
    //The result is Hello because = is assigning the value to $test and the second condition is false because it check the equality of $test to the value 2.
    

    I hope this will help.

提交回复
热议问题