<?php
function test($a="all"){
var_dump(in_array($a,array(0,1)));
}
test("all");
test(1);
Return two true
學(xué)習(xí)是最好的投資!
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
- 如果第三個參數(shù) strict 的值為 TRUE 則 in_array() 函數(shù)還會檢查 needle 的類型是否和 haystack 中的相同。
You need to use the third parameter.
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.
This is because there is a problem with converting strings to digits. var_dump('d'==0); true pure characters will be converted to 0