gpt4 book ai didi

PHP - 将两个数组合并为一个数组(也删除重复项)

转载 作者:IT老高 更新时间:2023-10-28 11:53:10 25 4
gpt4 key购买 nike

您好,我正在尝试合并两个数组,并且还想从最终数组中删除重复值。

这是我的数组 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

)

我想删除这些重复的条目,或者我可以在合并之前删除它们吗...请帮助..谢谢!!!!!!!

最佳答案

array_unique(array_merge($array1,$array2), SORT_REGULAR);

http://se2.php.net/manual/en/function.array-unique.php

关于PHP - 将两个数组合并为一个数组(也删除重复项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com