Error message
You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).function DatabaseStatementPrefetch::fetchAllKeyed
Returns the entire result set as a single associative array.
This method is only useful for two-column result sets. It will return an associative array where the key is one column from the result set and the value is another field. In most cases, the default of the first two columns is appropriate.
Note that this method will run the result set to the end.
Parameters
$key_index: The numeric index of the field to use as the array key.
$value_index: The numeric index of the field to use as the array value.
Return value
An associative array, or an empty array if there is no result set.
Overrides DatabaseStatementInterface::fetchAllKeyed
File
-
includes/
database/ prefetch.inc, line 479
Class
- DatabaseStatementPrefetch
- An implementation of DatabaseStatementInterface that prefetches all data.
Code
public function fetchAllKeyed($key_index = 0, $value_index = 1) {
if (!isset($this->columnNames [$key_index]) || !isset($this->columnNames [$value_index])) {
return array();
}
$key = $this->columnNames [$key_index];
$value = $this->columnNames [$value_index];
$result = array();
// Traverse the array as PHP would have done.
while (isset($this->currentRow )) {
$result[$this->currentRow [$key]] = $this->currentRow [$value];
$this->next ();
}
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.