function StatementWrapperIterator::fetchAllAssoc
Same name in other branches
- 11.x core/lib/Drupal/Core/Database/StatementWrapperIterator.php \Drupal\Core\Database\StatementWrapperIterator::fetchAllAssoc()
Overrides StatementInterface::fetchAllAssoc
File
-
core/
lib/ Drupal/ Core/ Database/ StatementWrapperIterator.php, line 166
Class
- StatementWrapperIterator
- StatementInterface iterator implementation.
Namespace
Drupal\Core\DatabaseCode
public function fetchAllAssoc($key, $fetch = NULL) {
if (isset($fetch)) {
if (is_string($fetch)) {
$this->setFetchMode(\PDO::FETCH_CLASS, $fetch);
}
else {
$this->setFetchMode($fetch);
}
}
// Return early if the statement was already fully traversed.
if (!$this->isResultsetIterable) {
return [];
}
// Once the while loop is completed, the resultset is marked so not to
// allow more fetching.
$return = [];
while ($record = $this->fetch()) {
$recordKey = is_object($record) ? $record->{$key} : $record[$key];
$return[$recordKey] = $record;
}
return $return;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.