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.
More Related Contents:
- Can I bind an array to an IN() condition in a PDO query?
- php pdo: get the columns name of a table
- PDO::fetchAll vs. PDO::fetch in a loop
- PDO fetch one column from table into 1-dimensional array
- PDO fetchAll array to one dimensional
- Using value of a column as index in results using PDO
- PDO prepared statement fetch() returning double results
- PHP/SQL Insert Error when using Named Placeholders
- how can I print multiple services in this way
- Remove Duplicates in array php
- Insert form in MySQL with PDO [duplicate]
- Undefined index $_POST
- Reference — frequently asked questions about PDO
- Getting raw SQL query string from PDO prepared statements
- PHP Sort a multidimensional array by element containing Y-m-d H:i:s date
- How to bind mysqli bind_param arguments dynamically in PHP?
- “Invalid parameter number: parameter was not defined” Inserting data
- Having issue with matching rows in the database using PDO
- php multi-dimensional array remove duplicate [duplicate]
- How can I properly use a PDO object for a parameterized SELECT query
- How is the PHP array implemented on the C level?
- Connect to SQL Server through PDO using SQL Server Driver
- Convert flat array to a delimited string to be saved in the database
- Group array data on one column and sum data from another column
- Check if specific array key exists in multidimensional array – PHP
- Re-index numeric array keys [duplicate]
- Getting a PHP PDO connection from a mysql_connect()?
- Reverse array in php
- Sort an array of associative arrays by column value
- Change array key without changing order