php in_array What's going on?
PHPz
PHPz 2017-06-06 09:53:41
0
3
1057
<?php
function test($a="all"){
    var_dump(in_array($a,array(0,1)));
}

test("all");

test(1);

Return two true

PHPz
PHPz

学习是最好的投资!

reply all(3)
小葫芦

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

- 如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。

You need to use the third parameter.

Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template