I am adding this here as I don’t seem to find any clear and easy to find examples and explanations of PDO::FETCH_GROUP and how it works by means of an example.
I find this to be one of the most useful modes available in fetchAll() when you need to work with any form of grouping.
In essence, PDO can group results into nested arrays, based on the first field selected.
Example
<?php
$data = $pdo->query('SELECT sex, name, car FROM users')->fetchAll(PDO::FETCH_GROUP);
?>
Tip: If you need to group the data by something other than the first field then you can do it like this as well
<?php
SELECT sex, users.* FROM users
?>