JsonRows
in package
implements
Countable, IteratorAggregate
Read several columns of the same length together, row by row.
Each row is built from the values of the columns at the same position, by a callback. The columns are read value by value, so the memory does not depend on the number of rows. The rows can be read several times.
Usage, to read the groups (parent, label) aggregated by the database: $groups = new JsonRows(array($parents, $labels), fn (array $values): array => $values); foreach ($groups as list($parent, $label)) { ... }
Tags
Table of Contents
Interfaces
- Countable
- IteratorAggregate
Properties
- $buildRow : Closure
- $columns : array<int, array<string|int, mixed>|JsonColumn|JsonRows>
Methods
- __construct() : mixed
- Create the rows from the columns.
- count() : int
- Get the number of rows: the number of values of the first column.
- getIterator() : Generator<int, mixed>
- Get the rows one by one.
Properties
$buildRow
private
Closure
$buildRow
The callback building a row from the values of the columns
$columns
private
array<int, array<string|int, mixed>|JsonColumn|JsonRows>
$columns
The columns
Methods
__construct()
Create the rows from the columns.
public
__construct(array<int, array<string|int, mixed>|JsonColumn|JsonRows> $columns, callable $buildRow) : mixed
Parameters
- $columns : array<int, array<string|int, mixed>|JsonColumn|JsonRows>
-
the columns, with the same number of values
- $buildRow : callable
-
the callback building a row from the list of the values of a row
count()
Get the number of rows: the number of values of the first column.
public
count() : int
Return values
int —the number of rows
getIterator()
Get the rows one by one.
public
getIterator() : Generator<int, mixed>
Return values
Generator<int, mixed> —the rows built by the callback