i have this array in php json.
i have made it to sort array by first Characther. but now i'm stuck on how to merge the data under the same title.
my response now is.
[
{
    "title": "A",
    "data": {
        "id": "317",
        "name": "Aesethetica"
    }
},
{
    "title": "A",
    "data": {
        "id": "318",
        "name": "Astonos"
    }
},
{
    "title": "B",
    "data": {
        "id": "320",
        "name": "Bourjois"
    }
},
{
    "title": "B",
    "data": {
        "id": "321",
        "name": "Bioderma"
    }
}
]
i need to merge all data under each same title. something like this:
[
    {
        "title": "A",
        "data": [
            {
            "id": "317",
            "name": "Aesethetica"
            },
            {
                "id": "318",
                "name": "Astonos"
            }
        ]
    },
    {
        "title": "B",
        "data": [
            {
                "id": "320",
                "name": "Bourjois"
            },
            {
                "id": "321",
                "name": "Bioderma"
            }
        ]
    }
]
kindly help. Thanks
i got this now: i made this update.. but still not the needed result.
this is my php code...
$result = [];
                foreach ($data as $item) {
                    $firstLetter = substr($item['name'], 0, 1);
                    $result[] = [
                        'title' => $firstLetter = ctype_alnum($firstLetter) ? $firstLetter : '#',
                        'data' => $item
                    ];
                }
    foreach ($result as $key => $item) {
       $arr[$item['title']][$key] = $item;
    }
and this is the result.
{
    "A": [
        {
            "title": "A",
            "data": {
                "brand_id": "312",
                "brand_name": "Adidsa"
            }
        },
        {
            "title": "A",
            "data": {
                "id": "314",
                "name": "Adio"
            }
        },
still can't find make the needed response..
 
    