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

后端 未结 9 2150
夕颜
夕颜 2020-12-08 00:35

I am not getting what is wrong with this code. It\'s returning \"Found\", which it should not.

$lead = \"418176000000069007\";
$diff = array(\"41817600000006         


        
9条回答
  •  情歌与酒
    2020-12-08 01:00

    If that is your problem and you really want to compare/find in array then there is a trick

    $lead = "a418176000000069007";
    $diff = array("a418176000000069003","a418176000000057001");
    
    if (in_array($lead,$diff))
        echo "Found";
    else
        echo "Not found";
    

    i.e. somehow you have to prepend a perticular character to every number. They will behave as strings in comparison and hence give correct result.

提交回复
热议问题