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)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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: