Home >Backend Development >PHP Tutorial >Things to note when using the php in_array function
PHP is a weakly typed language. When using the IN_ARRAY function, try to bring the third parameter. The code is as follows:
var_dump(in_array(0,array('s','sss'),true)); // return false
var_dump(in_array(0,array('s','sss'))); // return true
var_dump(in_array(0,array(1,2,3))); // return false
It can be seen from the above three functions that the first one: in_array(0,array('s','sss'),true) returns the value we want.
Use: var_dump( in_array(0,array('s','sss'))); and: var_dump(in_array(0,array(1,2,3)));
Returning true is obviously not the value we want, because the main reason PHP is a weak type, so it is better for you to pay attention to it before.