I'm dealing with an array structure like the following:
[
{
"ID": 227886,
"post_author": "54"
},
{
"ID": 227545,
"post_author": "18"
},
{
"ID": 229317,
"post_author": "22"
},
{
"img": "bang.jpg",
"id": 229317
},
{
"img": "other.png",
"id": 227886
},
{
"img": "name.jpg",
"id": 227545
}
]
My goal is to merge the objects with an "img" key into the objects whose "ID" matches the "img" object's "id" value.
The desired output should be:
[
{
"ID": 227886,
"post_author": "54",
"img": "other.png",
"id": 227886
},
{
"ID": 227545,
"post_author": "18",
"img": "name.jpg",
"id": 227545
},
{
"ID": 229317,
"post_author": "22",
"img": "bang.jpg",
"id": 229317
}
]
Is there a way to merge objects within the same array based on matching "id" and "ID" values?