While developing a PHP application, I ran into this strange quirk.
Apparently, the string '01' == '1'
, '05' == '5'
, '03111' == '3111'
.
I tried this -
php > $numbers = ["1", "2", "3", "4", "5"];
php > in_array("01", $numbers);
true
php > var_dump("01" == "1");
true
php > var_dump("00003333" == "3333")
true
How do I prevent this (i.e return false for the in_array
call) , and why is it happening in the first place?