PHP's in_array unexpected result

后端 未结 2 1142
夕颜
夕颜 2021-01-27 04:25

When I execute this small piece of PHP code:

php -r \"echo(in_array(0, array(\'aaa\', \'bbb\')));\"

That echoes true...

<
2条回答
  •  一生所求
    2021-01-27 04:49

    Also, check out this code:

       var_dump(0 == 'aaa');
       var_dump(0 === 'aaa');
       var_dump(in_array(0, array('aaa', 'bbb')));
       var_dump(in_array(0, array('aaa', 'bbb'), true));
    

    The last version allows strict type comparison so it will work as expected, that is return false.

提交回复
热议问题