Search code examples
phpoperatorsequality-operator

== and === operators in php


Let's 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 is

Which is quicker/best, using === (indentity) or the == (equality)?


Solution

  • Testing for identity is always faster, because PHP does not have to Type Juggle to evaluate the comparison. However, I'd say the speed difference is in the realms of nanoseconds and totally neglectable.

    Related reading: