How to differentiate "001" from "1" in PHP? [duplicate]

1

If I compare 001 and 1 in PHP, it gives a result that the numbers are identical! In fact it seems it is! How do I differentiate 1 from 001, treat each one as if it were different?

    
asked by anonymous 20.08.2015 / 00:21

1 answer

7

Something tells me that there is already an answer to this but as the search returns nothing, it goes:

The comparison ends up being coerced and both are converted to number, so 1 is equal to 1. To ensure that the comparison is correct, it has to compare with the operator that does not coerce, and it is === (identical). In fact, you should almost always use this operator and not == (equal). This operator is problematic because it does not consider the data type with unexpected results.

See running on ideone .

Documentation .

    
20.08.2015 / 00:26