Is there a way to fetch associative array grouped by the values of a specified column with PDO?

It’s quite old topic, but I found very easy solution:

->fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_UNIQUE)

First col will be set as key, rest will be set as value.

No need to walk over the array or use array_map.

Leave a Comment