<?php
var_dump(in_array('ddds', array(2,3,0)));
Why this function return true? We have a string which could be converted to 1 but why to 0?
<?php
var_dump(in_array('ddds', array(2,3,0)));
Why this function return true? We have a string which could be converted to 1 but why to 0?
This is because ddds == 0
is true (demo), and 0 is an element of your array. Set the strict
parameter for in_array()
to ensure the types are also considered.
From the documentation:
If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
var_dump( in_array('ddds', array(2,3,0), TRUE) );
Output:
bool(false)