【发布时间】:2012-11-08 07:40:03
【问题描述】:
您好,我正在尝试合并两个数组,并且还想从最终数组中删除重复值。
这是我的数组 1:
Array
(
[0] => stdClass Object
(
[ID] => 749
[post_author] => 1
[post_date] => 2012-11-20 06:26:07
[post_date_gmt] => 2012-11-20 06:26:07
)
这是我的数组 2:
Array
(
[0] => stdClass Object
(
[ID] => 749
[post_author] => 1
[post_date] => 2012-11-20 06:26:07
[post_date_gmt] => 2012-11-20 06:26:07
)
我使用array_merge 将两个数组合并为一个数组。它给出这样的输出
Array
(
[0] => stdClass Object
(
[ID] => 749
[post_author] => 1
[post_date] => 2012-11-20 06:26:07
[post_date_gmt] => 2012-11-20 06:26:07
[1] => stdClass Object
(
[ID] => 749
[post_author] => 1
[post_date] => 2012-11-20 06:26:07
[post_date_gmt] => 2012-11-20 06:26:07
)
我想删除这些重复的条目,或者我可以在合并之前删除它们吗... 请帮助.. 谢谢!!!!!!!
【问题讨论】:
-
因为你想合并 $array1[0] 和 $array2[0] 而不是 $array1 和 $array2。尝试在每个数组的第一项上运行 array_merge
-
数组是动态的..所以它不会总是 $array1[0] 和 $array2[0]
-
有什么东西可以用来比较数组中每个对象的ID???
-
忘记我的第一条评论不起作用,因为您要合并的不是数组而是对象。您必须手动完成
标签: php arrays wordpress multidimensional-array