<?php
function test($a="all"){
var_dump(in_array($a,array(0,1)));
}
test("all");
test(1);
Return two true
高洛峰2017-06-06 09:55:41
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
- 如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
You need to use the third parameter.
PHP中文网2017-06-06 09:55:41
PHP is a weakly typed language and will automatically convert variable types according to specific scenarios. The arrays you want to search are obviously all integers, so you can only convert the variables into integers. When pure characters are converted into integers, 0 is naturally included.
我想大声告诉你2017-06-06 09:55:41
This is because there is a problem with converting strings to digits. var_dump('d'==0); true pure characters will be converted to 0