Imagine that you have to query the database in order to retrieve some data (in this example names and ages):
while ($submission = db_fetch_array($submissions)) {
$data[] = $submission['data'];
}
So the resulting dump of the $data array would be something like:
Array
(
[0] = "John"
[1] = "33"
)
If I wanted to form descriptive keys, the resulting code would be:
while ($submission = db_fetch_array($submissions)) {
$data[] = $submission['data'];
}
$data['name'] = $data[0];
$data['age'] = $data[1];
Now if instead of only two fields in my array I would have 10 or more fields, this seems to me a little bit redundant.
Is there a more logical way to do this?
Note: db_fetch_array it’s a drupal abstraction in order to fetch a query as an array
Don’t now, what
db_*()should be, but I recommend to fetch the array as associative array direct from the databaseThis results in an array of associative arrays, where the keys of the inner associative arrays are the name of the columns.
http://php.net/pdostatement.fetch