In JavaScript, the ==
operator isn't necessarily transitive:
js> '0' == 0
true
js> 0 == ''
true
js> '0' == ''
false
Is the same true in PHP? Can you give an example?
Equal Operator == This operator accepts two inputs to compare and returns true value if both of the values are same (It compares only value of variable, not data types) and return a false value if both of the values are not same.
== Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. Syntax: operand1 == operand2. === Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.
1) When we compare two variables of different type e.g. a boolean with a string or a number with String using == operator, it automatically converts one type into another and return value based upon content equality, while === operator is strict equality operator in Java, and only return true if both variable of same ...
The inequality operator ( != ) checks whether its two operands are not equal, returning a Boolean result. Unlike the strict inequality operator, it attempts to convert and compare operands that are of different types.
No, the ==
operator is not transitive.
The exact same scenario gives the same result in PHP.
echo var_dump('0'==0);
echo var_dump(0=='');
echo var_dump('0'=='');
yields:
boolean true
boolean true
boolean false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With