我试图比较两个数组,php 返回以下错误:
Catchable fatal error: Object of class Node could not be converted to string in D:\projetos\labs\dok\dev\application\models\dok.php on line 410
我的数组分别是:
array(2)
object(Node)#5 ...[7 attributes]
object(Node)#6 ...[7 attributes]
array(1)
object(Node)#5 ....[7 attributes]
我真的很感谢这里的一些帮助,因为我不知道发生了什么。谢谢(:
根据要求,差异周围的代码:
// is it a distant child?
$all_childs = $node->get_childs(true);
$distant_childs = array_diff($all_childs, $childs);
if(in_array($this, $distant_childs))
return 'distant-child';
最佳答案
Note:
Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
如果元素是对象,则需要提供__toString()对象的方法,或者您自己完成。
关于php - array_diff() 无明显原因失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254884/