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

前端 未结 8 1422
轮回少年
轮回少年 2020-11-28 07:39

For example, let\'s use some simple data set

+---------+------+------+------------+
| name    | age  | sex  | position   |
+---------+------+------+---------         


        
8条回答
  •  無奈伤痛
    2020-11-28 08:15

    to reduce a unnecessary nesting array level:

    $res = $pdo->query('SELECT * FROM employee')->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
    $res = array_map('reset', $res);
    

提交回复
热议问题