Jump to content

Differences between double equations and triple equations


terryds

Recommended Posts

  • == will not do type casting, so 2 == "2" would be true.
  • === will check for type, so 2 === "2" would be false.

 

It is always best practice, IMO, to use ===, to make sure both the value and type of both sides are actually the same.

Edited by thescientist
Link to comment
Share on other sites

 

  • == will not do type casting, so 2 == "2" would be true.
  • === will check for type, so 2 === "2" would be false.

 

It is always best practice, IMO, to use ===, to make sure both the value and type of both sides are actually the same.

 

 

Personally, I don't use === unless the type is strictly important in the comparison (functions that can return both 0 and false with different meanings). Using == can simplify things, like not having to type cast a variable before comparing it. You know all $_POST, $_GET and $_COOKIE values are strings, so when you want to compare them to a number it's simpler to use == than to cast them.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...