== and === operators in php

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

Which is faster / better using === (indentity) or == (equality)?

+4
source share
3 answers

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:

+6
source

=== 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.

+2
source

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.

0
source

All Articles