function FetchModeTrait::assocToColumn

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Database/FetchModeTrait.php \Drupal\Core\Database\FetchModeTrait::assocToColumn()
  2. 10 core/lib/Drupal/Core/Database/FetchModeTrait.php \Drupal\Core\Database\FetchModeTrait::assocToColumn()

Converts a row of data in associative format to column.

Parameters

array $rowAssoc: A row of data in associative format.

string[] $columnNames: The list of the row columns.

int $columnIndex: The index of the column to fetch the value of.

Return value

string The value of the column.

Throws

\ValueError If the column index is not defined.

File

core/lib/Drupal/Core/Database/FetchModeTrait.php, line 75

Class

FetchModeTrait
Provide helper methods for statement fetching.

Namespace

Drupal\Core\Database

Code

protected function assocToColumn(array $rowAssoc, array $columnNames, int $columnIndex) : mixed {
  if (!isset($columnNames[$columnIndex])) {
    throw new \ValueError('Invalid column index');
  }
  return $rowAssoc[$columnNames[$columnIndex]];
}

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