Skip to main content

How to get Duplicated Keys into one Key with all Key values

I have this following code, I have a list of Items: Date: 0 GameId 0 GameValue 1 Date: 0 GameId 0 GameValue 2 Date: 0 GameId 1 GameValue 1 Date: 0 GameId 1 GameValue 1

And I want to loop all of the items to get this:

 $newArray[] = array($gameId => array($gameValue))

My Code :

foreach ($games as $ga) {
        $gamedId = $ga["gameId"];
        $gameValue = $k["gameValue"];
        $result[] = array($gameId => array($gameValue));
    };

What Can I do to remove all duplicate Ids and get all the Value with same Id?



source https://stackoverflow.com/questions/69713044/how-to-get-duplicated-keys-into-one-key-with-all-key-values

Comments