php - array_diff() 无明显原因失败

标签 php arrays

我试图比较两个数组,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/

相关文章:

PHP 包含多个文件试图合并 SQL 查询

java - 检查两个 int 数组是否相等 - 无论顺序如何

ios - UITableView-从两个数组切换数据

c++ - 使用二维数组作为一维数组是否正确?可能导致未定义的行为等等?

javascript - 检测数组中的任何元素是否包含连字符

c - 用于嵌入式系统的 C 中最快的数组查找算法?

php - 除了每个用户单独的数据库之外还有其他选择吗?

php - 如何发送主题含有特殊字符的电子邮件?

javascript - 从 PHP 到 Javascript 的数组处理

php - 如何在 PHP 中处理大于 16 位的值?