和array_diff()不无明显原因

问题描述:

我试图diff的两个数组和PHP还是返回了以下错误:和array_diff()不无明显原因

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] 

我真的欣赏一些帮助,因为我不知道发生了什么。谢谢(:


的要求,围绕DIFF代码:

// 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'; 
+0

这将有助于看到这个 – AlexC 2012-02-13 02:38:42

Note:

Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

如果元素是对象,你需要为对象提供__toString()方法,或者您做到了

+2

哇!它只是用'simple serialize()'工作!我不得不承认,我看到这是一个PHP“错误”:( – 2012-02-13 02:44:38