2012-02-13 50 views
2

我試圖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

回答

2

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