public function Statement::fetchAllKeyed in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Database/Statement.php \Drupal\Core\Database\Statement::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 StatementInterface::fetchAllKeyed
File
- core/
lib/ Drupal/ Core/ Database/ Statement.php, line 108
Class
- Statement
- Default implementation of StatementInterface.
Namespace
Drupal\Core\DatabaseCode
public function fetchAllKeyed($key_index = 0, $value_index = 1) {
$return = [];
$this
->setFetchMode(\PDO::FETCH_NUM);
foreach ($this as $record) {
$return[$record[$key_index]] = $record[$value_index];
}
return $return;
}