class included{}class test{ public $arr = array(); function a(included $include){ if (in_array($include, $this->arr, true)){ return; } $this->arr[] = $include; }}$test = new test();$test->a(new included());$test->a(new included());$test->a(new included());print_r($test->arr); // 输出array ( [0] => included object ( ) [1] => included object ( ) [2] => included object ( ) )
bool in_array ( mixed $needle , array $haystack [, bool $strict = false ] )
如果第三个参数 strict 的值为 true 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
这个类型是否可以理解为对象实例。 因为上面的例子中的in_array()第三个参数默认的时候,只有输出
array ( [0] => included object ( ) )
回复讨论(解决方案) 是的,这个类型同样包括对象实例
恩,谢谢您了。
第三?是?查是否相同?型的。
例如:
谢谢楼上,但是这个类型相同是否是包含对象实例,这个php手册里没有这方面的描述。
手册中是这样描述的
如果第三个参数 strict 的值为 true 则 in_array() 函数还会检查 needle 的 类型是否和 haystack 中的相同。
那个类型是个链接,点开后是
这就不需要再细说了吧?
而况你实测的结果也是包括对象的
好的,谢谢了。