Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

== 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)?

like image 354
Lizard Avatar asked Feb 27 '23 20:02

Lizard


1 Answers

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:

  • PHP type comparison tables
  • Type Juggling
like image 70
Gordon Avatar answered Mar 04 '23 21:03

Gordon