Reference

Guide

$collection->when()

The when method only executes the given Closure when the first parameter is true. If the first parameter is false, the Closure will not be executed.

$collection->when(mixed $condition, Closure $callback, Closure $fallback = null): mixed

Parameters

Name Type Default Description
$condition mixed
$callback Closure
$fallback Closure null

Return type

mixed

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L1072