|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-29 15:31 UTC] eric dot schultz at cyvon dot com
Description:
------------
I would love if the pg_fetch_all could take a parameter that would (optionally) allow the indexing of the resultset to be a column value as opposed to 0-based. (as many tables include a primary key/id)
Reproduce code:
---------------
---
From manual page: function.pg-fetch-all
---
I find myself doing the following VERY often:
$res = pg_query("Select * from set_options");
if(!$res) return(0);
$ret = array();
while($r = pg_fetch_assoc($res)){
$ret[$r['id']] = $r; }
return($ret);
Expected result:
----------------
above produces an associative array indexed on the "id" column. Would like this built into the pg_fetch_all
Actual result:
--------------
see above
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 05:00:01 2025 UTC |
I forgot about compound keys. Therefore, it's simply cannot be done. You can convert it with one line. <?php $res = array(array('id'=>1, 'a'=>'abc'), array('id'=>2, 'a'=>'xyz')); array_walk($res, function($e, $k) use (&$new) {$new[$e['id']] = $e;}); var_dump($new);