function StatementPrefetch::fetchAllKeyed

Same name in other branches
  1. 9 core/lib/Drupal/Core/Database/StatementPrefetch.php \Drupal\Core\Database\StatementPrefetch::fetchAllKeyed()
  2. 10 core/lib/Drupal/Core/Database/StatementPrefetch.php \Drupal\Core\Database\StatementPrefetch::fetchAllKeyed()

Overrides StatementInterface::fetchAllKeyed

File

core/lib/Drupal/Core/Database/StatementPrefetch.php, line 511

Class

StatementPrefetch
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 = [];
    // 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.