Take While

Take elements from the start of an array while a condition is true.

Code

General
$result = [];
foreach ($arr as $v) {
    if ($v >= $threshold) break;
    $result[] = $v;
}
return $result;

Parameters

Array to process

Take while less than threshold

Server

More PHP Snippets