array_unique在排序数组时输出null

时间:2017-10-13 13:49:29

标签: php arrays array-unique

我有这个数组(从JSON解码,用print_r输出):

windeployqt -help

但现在我必须删除所有重复项。 如果我尝试stdClass Object ( [data] => Array ( [0] => stdClass Object ( [item] => te [date] => 13.10 ) [1] => stdClass Object ( [item] => te [date] => 13.10 ) [2] => stdClass Object ( [item] => tr [date] => 13.10 ) ) ) $result = array_unique($array, SORT_REGULAR);为空。

有人可以发现我的错误吗?

1 个答案:

答案 0 :(得分:3)

这是 stdClass 对象,而不是数组。使用函数 json_decode 进行解码时,需要传递参数" true"有一个数组:

$array = json_decode($json, true);

编辑:正如人们在评论中注意到的那样,实际数组存在于$array['data']中,因此array_unique必须应用于$array['data']而不是$array