0

(Simplification)
I have a table [id][username]
Would like when I fetch all from table NOT TO GET

[
0=>[10,'unam1'],
1=>[20,'unam2'], ...
]

but rather use the record ID as the array key. Is there a way in php5.4? I use PDO.

[
10=>[10,'unam1'],
20=>[20,'unam2'], ...
]

OR

[
10=>['unam1'],
20=>['unam2'], ...
]
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
  • I think this answer will help you. http://stackoverflow.com/a/15528833/2816475 – Ronin Oct 06 '13 at 21:47
  • possible duplicate of [PDO associative arrays - return associative](http://stackoverflow.com/questions/15512861/pdo-associative-arrays-return-associative) – Ronin Oct 06 '13 at 21:49
  • This way you two suggest is using PHP to format the array, I am familiar with such ways. I am wondering if PHP has a native function for that very common need. – Itay Moav -Malimovka Oct 07 '13 at 10:43
  • Maybe using `PDOStatement::fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP)` will return similar result. It will group records by the first column. More information here: http://www.php.net/manual/en/pdostatement.fetchall.php – Ronin Oct 07 '13 at 19:14

0 Answers0