Skip to content

Commit

Permalink
Update docs [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 21, 2024
1 parent c7c389a commit 4e01655
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/ArArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,24 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
}

/**
* Returns the value of an array element or {@see ActiveRecordInterface} instance property by the given path.
* Populates an array of rows with the specified column value as keys.
*
* This method is internally used to populate the data fetched from a database using `$indexBy` parameter.
* The input array should be multidimensional or an array of {@see ActiveRecordInterface} instances.
*
* For example,
*
* ```php
* $rows = [
* ['id' => '123', 'data' => 'abc'],
* ['id' => '345', 'data' => 'def'],
* ];
* $result = ArArrayHelper::populate($rows, 'id');
* // the result is: ['123' => ['id' => '123', 'data' => 'abc'], '345' => ['id' => '345', 'data' => 'def']]
* ```
*
* @param array[] $rows The raw query result from a database.
* @param array[] $rows Array to populate.
* @param Closure|string|null $indexBy The column name or anonymous function that specifies the index by which to
* populate the array of rows.
*
* @psalm-template TRow of Row
* @psalm-param array<TRow> $rows
Expand Down

0 comments on commit 4e01655

Please sign in to comment.