Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

petritr's avatar
Level 15

filter duplicated array collections

I have an collection like this:

Collection {#560 ▼
  #items: array:3 [▼
    429 => array:3 [▼
      0 => array:5 [▼
        "id" => 1242
        "post_id" => 2040
        "post" => array:21 [▶]
      ]
      1 => array:5 [▼
        "id" => 1245
        "post_id" => 2047
        "post" => array:21 [▶]
      ]
    ]
    430 => array:3 [▼
      0 => array:5 [▼
        "id" => 1243
        "post_id" => 2040
        "post" => array:21 [▶]
      ]
    431 => array:3 [▼
      0 => array:5 [▼
        "id" => 1245
        "post_id" => 2041
        "post" => array:21 [▶]
      ]
      1 => array:5 [▼
        "id" => 1244
        "post_id" => 2047
        "post" => array:21 [▶]
      ]
    ]
  ]
}

if the post_idlike 2040 and 2047 from array 429 is found in the other array 431 then return only the only array 431 so i would have the duplicated removed

0 likes
3 replies
petritr's avatar
Level 15

wont work directly with unique since its a nested array collection

bobbybouwmann's avatar

You can still write the logic to return all the items in one of the collections items that determine the unique value.

Please or to participate in this conversation.