Skip to content
Search
Examples

Transformations

Description

Add conditional logic to your transformations. Evaluate a condition and return different values based on whether it's true or false—similar to an if/else statement.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{data_frame, from_array, lit, ref, to_output, when};

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

data_frame()
    ->read(from_array([
        ['id' => 1, 'email' => '[email protected]', 'active' => true, 'tags' => ['foo', 'bar']],
        ['id' => 2, 'email' => '[email protected]', 'active' => false, 'tags' => ['biz', 'bar']],
        ['id' => 3, 'email' => '[email protected]', 'active' => true, 'tags' => ['bar', 'baz']],
    ]))
    ->collect()
    ->withEntry(
        'is_special',
        when(
            ref('active')->isTrue()->and(ref('tags')->contains('foo')),
            lit(true),
            lit(false)
        )
    )
    ->write(to_output(truncate: false))
    ->run();
Contributors

Built in the open.

Join us on GitHub
scroll back to top