为什么PHP in_array返回true(当它不应该)? [英] Why PHP in_array returns true (when it shouldn't)?

查看:175
本文介绍了为什么PHP in_array返回true(当它不应该)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关这个数组($选项)

Array
 (
[0] => 0
[1] => 1
[2] => 2
 )

PHP返回TRUE:

PHP returns TRUE:

    $this->assertTrue( in_array('Bug', $options ) );         // TRUE
    $this->assertTrue( in_array('Feature', $options ) );     // TRUE
    $this->assertTrue( in_array('Task', $options ) );        // TRUE
    $this->assertTrue( in_array('RockAndRoll', $options ) ); //TRUE  

为什么?

推荐答案

这是因为 0 = =串是真实 0 是数组的元素。

This is because 0 == "string" is true, and 0 is an element of the array.

位于 in_array 参数 $严格为true:

$this->assertTrue( in_array('Bug', $options, true) );

这篇关于为什么PHP in_array返回true(当它不应该)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆