Re arrange multidimentional array

I have an multi dimensional array i am trying to group the array based on the duplicate value.

So, I’m trying to group them by key but i am not getting to group the array based on the key values.

Below is the original array

[
        {
            "league_id": 2,
            "league_name": "BBBB",
            "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1722361078.png",
            "order_number": 1,
            "member_username": "A"
        },
        {
            "league_id": 2,
            "league_name": "BBBB",
            "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1722361078.png",
            "order_number": 2,
            "member_username": "B"
        },
        {
            "league_id": 1,
            "league_name": "AAAA",
            "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1724177635.png",
            "order_number": 1,
            "member_username": "C"
        },
        {
            "league_id": 1,
            "league_name": "AAAA",
            "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1724177635.png",
            "order_number": 2,
            "member_username": "D"
        },
    ]

I want to rearrange this array as output array below:

[
    {
        "league_id": 2,
        "league_name": "BBBB",
        "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1722361078.png",
        "users": [{
            "order_number": 1,
            "member_username": "A"
        }, {
            "order_number": 2,
            "member_username": "B"
        }]
    },
    {
        "league_id": 1,
        "league_name": "AAAA",
        "league_image": "https://d2ayu7u0r0spqb.cloudfront.net/dev/league-images/1722361078.png",
        "users": [{
            "order_number": 1,
            "member_username": "C"
        }, {
            "order_number": 2,
            "member_username": "D"
        }]
    }
]

Any idea? How to do this.

Thanks