Say I have a variable that will always be a string.
Now take the code below:
if($myVar === "teststring")
Note: $myVar will always be a string, so my questions
$myVar
Which is faster / better using === (indentity) or == (equality)?
===
==
Identity testing is always faster because PHP does not have to introduce Juggle to evaluate comparisons. However, I would say that the difference in speed is in the spheres of nanoseconds and is completely negligible.
Related reading:
=== will be a little faster, but more importantly, it ensures that $myVar will be a string, so you donβt have to worry about the possible consequences of being some other type.
In general, when I code, I use == over ===, however, using the identifier is more accurate and also a little faster (the difference is minimal).
The difference between the two is probably not relevant to what you need.