function StatementPrefetchIterator::fetchAllKeyed

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::fetchAllKeyed()

Overrides StatementInterface::fetchAllKeyed

File

core/lib/Drupal/Core/Database/StatementPrefetchIterator.php, line 361

Class

StatementPrefetchIterator
An implementation of StatementInterface that prefetches all data.

Namespace

Drupal\Core\Database

Code

public function fetchAllKeyed($key_index = 0, $value_index = 1) {
    if (!isset($this->columnNames[$key_index]) || !isset($this->columnNames[$value_index])) {
        return [];
    }
    $key = $this->columnNames[$key_index];
    $value = $this->columnNames[$value_index];
    $result = [];
    while ($row = $this->fetch(\PDO::FETCH_ASSOC)) {
        $result[$row[$key]] = $row[$value];
    }
    return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.