Chain multiple conditions for multi-tier logic, similar to if-elseif-else chains. Useful for categorizing data into multiple levels, implementing grading systems, or determining status based on several criteria.
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, 'score' => 95, 'email' => '[email protected]'],
['id' => 2, 'score' => 75, 'email' => '[email protected]'],
['id' => 3, 'score' => 55, 'email' => '[email protected]'],
['id' => 4, 'score' => 30, 'email' => '[email protected]'],
]))
->collect()
->withEntry(
'grade',
when(
ref('score')->greaterThanEqual(lit(90)),
lit('A'),
when(
ref('score')->greaterThanEqual(lit(70)),
lit('B'),
when(
ref('score')->greaterThanEqual(lit(50)),
lit('C'),
lit('F')
)
)
)
)
->write(to_output(truncate: false))
->run();