Note. this behavior has been changed in PHP 5.4.
By default, in_array uses free comparison ( == ), which means that numeric strings are converted to numbers and compared as numbers. Prior to PHP 5.4, if you did not have sufficient accuracy in your platform floating form, the difference was lost and you received the wrong answer.
The solution is to enable strict comparison ( === ) by passing an extra Boolean parameter to in_array :
$lead = "418176000000069007"; $diff = array("418176000000069003", "418176000000057001"); if ( in_array($lead, $diff, true) ) echo "Found"; else echo "Not found";
Then the strings are compared as strings without numerical coercion. However, this means that you are losing the standard equivalence of strings such as "01234" and "1234".
This behavior was reported as a bug and fixed in PHP 5.4. Numeric strings are still converted to numbers compared to == , but only if the string value matches the platform's numerical type.
Mark Reed May 02 '12 at 6:34 a.m. 2012-02-02 06:34 a.m.
source share