What does “===” mean?

前端 未结 10 1300
一生所求
一生所求 2020-11-27 06:01

I\'ve noticed someone using the PHP operator === which I can\'t make sense out of. I\'ve tried it with a function, and it corresponds in crazy ways.

Wha

相关标签:
10条回答
  • 2020-11-27 06:47

    http://www.php.net/ternary

    $a == $b Equal TRUE if $a is equal to $b, except for (True == -1) which is still True.

    $a === $b Identical TRUE if $a is equal to $b, and they are of the same type.

    > "5" == 5;
    True
    > "5" === 5;
    False
    
    0 讨论(0)
  • 2020-11-27 06:49

    See Double and Triple equals operator in PHP that I got for googling on "PHP three equals operator".

    At one point it says that:

    A double = sign is a comparison and tests whether the variable / expression / constant to the left has the same value as the variable / expression / constant to the right.

    A triple = sign is a comparison to see whether two variables / expresions / constants are equal AND have the same type - i.e. both are strings or both are integers.

    It also gives an example to explain it.

    0 讨论(0)
  • 2020-11-27 06:52

    For PHP, there many different meanings a zero can take

    1. it can be a Boolean false
    2. it could be a null value
    3. It could really be a zero

    So === is added to ensure the type and the value are the same.

    0 讨论(0)
  • 2020-11-27 06:52

    "===" matching the value in the variable as well as data type of the variable.

    0 讨论(0)
提交回复
热议问题