将多个JSON对象合并为单个对象,并将不相等的数据作为数组添加到此对象中

I have a Laravel join database query which returns me this:

[
  {
    "post_id": 28,
    "site_id": 16,
    "url": "http://something.com",
    "title": "Website title",
    "post_created_at": "2015-07-06 02:40:01",
    "post_updated_at": "2015-09-08 22:33:20",
    "tag_map_id": 11,
    "tag_id": 9,
    "tag_name": "dog"
  },
  {
    "post_id": 28,
    "site_id": 16,
    "url": "http://something.com",
    "title": "Website title",
    "post_created_at": "2015-07-06 02:40:01",
    "post_updated_at": "2015-09-08 22:33:20",
    "tag_map_id": 12,
    "tag_id": 10,
    "tag_name": "cat"
  }
]

So there can be multiple results with same post_id but one post can also have multiple tags.

What I want, is to merge these multiple results into one JSON object which contains all the tag-related stuff in array. So there should be only one JSON-object per one post_id. Like the example below:

[
  {
    "post_id": 28,
    "site_id": 16,
    "url": "http://something.com",
    "title": "Website title",
    "post_created_at": "2015-07-06 02:40:01",
    "post_updated_at": "2015-09-08 22:33:20",
    "tag_map_id": [11, 12],
    "tag_id": [9, 10],
    "tag_name": ["dog", "cat"]
  }
]

How can I achieve this merging in PHP?

I wouldn't use join at all. I would use Eloquent,

Post::with('tags')

and then use json_encode() on the resulting Collection.