Why does in_array() wrongly return true with these (large numeric) strings?

arrays, php

Solution

Note: This was a bug in PHP old versions and is corrected in `PHP 5.4` and newer versions.

It is because of the limitations of the number storage in `PHP`

The real problem here is because of the `PHP_INT_MAX` - the value exceeded in our case.

Try to `echo`/`print_r` `$lead` and `$diff` without using the quotes. It will result

$lead ---> 418176000000070000  
$diff ---> Array ( [0] => 418176000000070000 [1] => 418176000000060000 )

so, in this case, the `in_array` result is true!

so use `strict` comparison in `in_array()` by setting third argument in `in_array()` as `true`

     if(in_array($lead,$diff,true)) //use type too
       echo "Found";
     else
       echo "Not found";
?>

Try this. It will work.

Problem

I am not getting what is wrong with this code. It's returning "Found", which it should not. ``` $lead = "418176000000069007"; $diff = array("418176000000069003","418176000000057001"); if (in_array($lead,$diff)) echo "Found"; else echo "Not found"; ```

Original source