Array
Static array helpers for working with lists of rows: pluck a field from every item, find the first item whose field matches, turn rows into id-keyed lookup maps, and build a positional placeholder list.
This page is a pure reference. For how the framework fits together, see the Guide.
ArrayUtils- static helpers for plucking fields, finding rows, and building maps from arrays.
ArrayUtils
The main class: static functions that operate on an array, listed alphabetically. Several work on arrays whose items are associative arrays or objects, reading a named field from each.
Field
ArrayUtils::Field(array &$array, string $fieldName): array
Pluck one field from every item, where each item is an associative array, returning the collected values in order.
| Name | Type | Description |
|---|---|---|
$array | array | The array of associative-array items to read from. |
$fieldName | string | The key to read from each item. |
Returns array The value of that key from each item.
FindFirst
ArrayUtils::FindFirst(array &$array, string $haystackFieldName, string $needle): mixed
Find the first item, each an associative array, whose named field is identical to the needle.
| Name | Type | Description |
|---|---|---|
$array | array | The array of associative-array items to search. |
$haystackFieldName | string | The key on each item to compare. |
$needle | string | The value to match against. |
Returns mixed The first matching item, or false when none matches.
ObjectField
ArrayUtils::ObjectField(array &$array, string $fieldName): array
Pluck one property from every item, where each item is an object, returning the collected values in order.
| Name | Type | Description |
|---|---|---|
$array | array | The array of objects to read from. |
$fieldName | string | The property to read from each item. |
Returns array The value of that property from each item.
ObjectFindFirst
ArrayUtils::ObjectFindFirst(array &$array, string $haystackFieldName, string $needle): mixed
Find the first item, each an object, whose named property is identical to the needle.
| Name | Type | Description |
|---|---|---|
$array | array | The array of objects to search. |
$haystackFieldName | string | The property on each item to compare. |
$needle | string | The value to match against. |
Returns mixed The first matching item, or false when none matches.
PositionalBindingFactory
ArrayUtils::PositionalBindingFactory(array|stdClass $items): string
Build a comma-separated list of question-mark placeholders, one for each item, for use as positional bindings.
| Name | Type | Description |
|---|---|---|
$items | array|stdClass | The items to count; an object is treated as its array of values. |
Returns string A comma-separated string of one placeholder per item.
RowsToArray
ArrayUtils::RowsToArray(array $rows, string $idFieldName, string $nameFieldName): array
Turn a list of row objects into a map from each row's id field to its name field.
| Name | Type | Description |
|---|---|---|
$rows | array | The row objects to convert. |
$idFieldName | string | The property used as the map key. |
$nameFieldName | string | The property used as the map value. |
Returns array A map of id value to name value.
RowsToMap
ArrayUtils::RowsToMap(array $rows, string $idFieldName): array
Turn a list of row objects into a map from each row's id field to the row itself.
| Name | Type | Description |
|---|---|---|
$rows | array | The row objects to convert. |
$idFieldName | string | The property used as the map key. |
Returns array A map of id value to the row.