繁体   English   中英

从一组数组中删除重复项

[英]remove duplicates from a group of arrays

我在一个数组中有以下一组数组,其中它们的内容是一组帖子:

array:5 [▼
  "in" => array:2 [▼
    0 => {#371 ▼
      +"id": 61
      +"created_at": "2019-11-29 08:12:11"
      +"updated_at": "2019-11-29 08:12:11"
      +"title": "Sports test "
      +"body": "Test answer"
      +"ttype": 0
      +"cat": 0
      +"a_id": 61
      +"tag": ""
    }
    1 => {#372 ▶}
  ]
  "out" => []
  "other" => []
  "fol" => array:17 [▶]
  "tag" => []
]

数组:

    $Final_updts['in'] = $all_update_in;
     $Final_updts['out'] = $all_update_out;
     $Final_updts['other'] = $all_update_oth;
     $Final_updts['fol'] = $follow_psts;
     $Final_updts['tag'] = $post_tags;

可能有一些帖子在多个数组中重复。 我尝试使用array_unique($Final_updts); ,但收到Error exception: Array to string conversion

有什么简单的方法可以做到这一点,或者我必须修改 5 个查询以防止任何重复的结果?

我假设您想通过 id 获取唯一项目。 让我们使用集合来解决这个问题。

$results = collect($array)->collapse()->unique('id');

请让我知道我是否做对了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM