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.
UNIFIED DATA PROCESSING FRAMEWORK
composer require flow-php/etl ~0.33.0 Extracts
Read from various data sources.
Transforms
Shape and optimize for your needs.
Loads
Store and secure in one of many available data sinks.
Examples:
Description
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();