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?
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?
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 .