0

I don't understand the difference between equal and identical

Hey guys, Can you help me with my problem ? Thx for any answer ^^

30th Dec 2016, 6:55 PM
Ryuzaki
7 Antworten
+ 5
Basically an equal operator is more lenient on the datatypes, you can do a 3 == "3" and it will still output a true. But an identical operator is more strict, 3 === "3" will simply output a false. Meaning that in identical operator not only wants you to have a same value, it wants you to have a same datatype to output a true.
30th Dec 2016, 8:11 PM
Wen Qin
Wen Qin - avatar
+ 4
It's pretty simple. Let's say that you have three variables: $a = 1 $b = "1" $c = 1 == (equal) is used to determine if the variables have the same value. === (identical) is used to determine if the variables have the same value and same data type. In this case you would use == (equal) to check if they have the same values. So, $a == $c But, $a is an Integer and $b is a string, so they're not identical because they're not the same data type and same value therefore $a !=== $b.
30th Dec 2016, 7:08 PM
Sam White
Sam White - avatar
+ 1
"==" will check value of operator, "===" will check value and type. For example: _______ 1 == "1" --> true 1 === "1" --> false, because you compare int and String :)
30th Dec 2016, 7:05 PM
Heroes Killer
Heroes Killer - avatar
+ 1
You are not right. Try to compile this: if("1" == 1) echo "true"; else echo "false";
30th Dec 2016, 8:09 PM
Heroes Killer
Heroes Killer - avatar
30th Dec 2016, 8:14 PM
Heroes Killer
Heroes Killer - avatar
+ 1
hey frnd I haven't gone through the java so.....I m declining..
8th Jan 2017, 3:15 AM
Pranshu Ranjan
Pranshu Ranjan - avatar
0
@Heroes Killer 1 == "1" would also return false because an Integer will never be equal to a string.
30th Dec 2016, 7:10 PM
Sam White
Sam White - avatar