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.

Classes
  • 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.

NameTypeDescription
$arrayarrayThe array of associative-array items to read from.
$fieldNamestringThe 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.

NameTypeDescription
$arrayarrayThe array of associative-array items to search.
$haystackFieldNamestringThe key on each item to compare.
$needlestringThe 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.

NameTypeDescription
$arrayarrayThe array of objects to read from.
$fieldNamestringThe 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.

NameTypeDescription
$arrayarrayThe array of objects to search.
$haystackFieldNamestringThe property on each item to compare.
$needlestringThe 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.

NameTypeDescription
$itemsarray|stdClassThe 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.

NameTypeDescription
$rowsarrayThe row objects to convert.
$idFieldNamestringThe property used as the map key.
$nameFieldNamestringThe 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.

NameTypeDescription
$rowsarrayThe row objects to convert.
$idFieldNamestringThe property used as the map key.

Returns array A map of id value to the row.