function ResultBase::fetchAllAssoc
Returns the result set as an associative array keyed by the given column.
If the given column appears multiple times, later records will overwrite earlier ones.
Parameters
string $column: The name of the field on which to index the array.
\Drupal\Core\Database\FetchAs $mode: One of the cases of the FetchAs enum. If set to FetchAs::Associative or FetchAs::List the returned value with be an array of arrays. For any other value it will be an array of objects. If not specified, defaults to what is specified by setFetchMode().
array{class?: class-string, constructor_args?: list<mixed>, column?: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions: An array of fetch options.
Return value
array An associative array, or an empty array if there is no result set.
File
-
core/
lib/ Drupal/ Core/ Database/ Statement/ ResultBase.php, line 134
Class
- ResultBase
- Base class for results of a data query language (DQL) statement.
Namespace
Drupal\Core\Database\StatementCode
public function fetchAllAssoc(string $column, FetchAs $mode, array $fetchOptions) : array {
$result = [];
while ($rowAssoc = $this->fetch(FetchAs::Associative, [])) {
$result[$rowAssoc[$column]] = $this->assocToFetchMode($rowAssoc, $mode, $fetchOptions);
}
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.