Skip to content
Search

Get the first value of a column in PHP

Take the value of the first row with first() inside aggregate(). The result depends on the row order, so sort before you rely on it.

code.php
<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{first, data_frame, from_array, int_schema, ref, schema, to_output};

require __DIR__ . '/vendor/autoload.php';

data_frame()
    ->read(from_array(
        [['a' => 100], ['a' => 100], ['a' => 200], ['a' => 400], ['a' => 400]],
        schema(int_schema('a')),
    ))
    ->aggregate([first(ref('a'))])
    ->write(to_output(truncate: false))
    ->run();
Contributors

Built in the open.

Join us on GitHub
scroll back to top