This code:
var_dump(in_array("000", array(",00", ".00")));
var_dump(in_array("111", array(",11", ".11")));
output:
bool(true)
bool(false)
Why does the first line return true ?
It has to do with PHP's type coercion. The "000" essentially gets converted to just 0. To force it to use strict type checking, in_array() accepts a third parameter.
var_dump(in_array("000", array(",00", ".00"), true));
output:
bool(false)
EDIT: @andrekeller also pointed out the ".00" probably gets converted to int 0 as well. Moral of the story, don't trust PHP to get types right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With