flow php

UNIFIED DATA PROCESSING FRAMEWORK

composer require flow-php/etl ~0.25.0

ChangelogRelease Cycle

elephant
extract

Extracts

Read from various data sources.

arrow
transform

Transforms

Shape and optimize for your needs.

arrow
load

Loads

Store and secure in one of many available data sinks.

Examples:

Description

Basic data filtering using the filter() method.

The filter() method allows you to remove rows from your dataset based on conditions. Only rows that match the condition will be kept in the result.

filter(BooleanExpression $condition): DataFrame

In this example, we filter the dataset to keep only rows where the active column is true. This is one of the most common operations in data processing - selecting a subset of data that meets specific criteria.

The filter expression uses Flow's DSL to reference columns and apply conditions:

  • ref('active') - References the 'active' column
  • isTrue() - Checks if the value is true

After filtering, only the active users (Alice, Charlie, and Diana) remain in the output.

composer.json
{
    "name": "flow-php/examples",
    "description": "Flow PHP - Examples",
    "license": "MIT",
    "type": "library",
    "require": {
        "flow-php/etl": "1.x-dev"
    },
    "minimum-stability": "dev"
}
code.php
<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{data_frame, from_array, ref, to_stream};

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

data_frame()
    ->read(from_array([
        ['id' => 1, 'name' => 'Alice', 'age' => 25, 'active' => true],
        ['id' => 2, 'name' => 'Bob', 'age' => 32, 'active' => false],
        ['id' => 3, 'name' => 'Charlie', 'age' => 28, 'active' => true],
        ['id' => 4, 'name' => 'Diana', 'age' => 35, 'active' => true],
        ['id' => 5, 'name' => 'Eve', 'age' => 22, 'active' => false],
    ]))
    ->collect()
    ->filter(ref('active')->isTrue())
    ->write(to_stream(__DIR__ . '/output.txt', truncate: false))
    ->run();

Output

+----+---------+-----+--------+
| id |    name | age | active |
+----+---------+-----+--------+
|  1 |   Alice |  25 |   true |
|  3 | Charlie |  28 |   true |
|  4 |   Diana |  35 |   true |
+----+---------+-----+--------+
3 rows

Contributors

Join us on GitHub external resource
scroll back to top