A::find()
Finds the first element matching the given callback
A::find(array $array, callable(mixed $value, (int|string) $key, array $array): bool $callback): mixed
Parameters
| Name | Type | Default |
|---|---|---|
| $arrayrequired | array |
no default value |
| $callbackrequired | callable(mixed $value, (intorstring) $key, array $array): bool |
no default value |
Return type
mixed
Parent class
Examples
$array = [1, 30, 39, 29, 10, 13];
$isAboveThreshold = fn($value) => $value > 30;
echo A::find($array, $isAboveThreshold);
// output: '39'
$array = [
'cat' => 'miao',
'cow' => 'moo',
'colibri' => 'humm',
'dog' => 'wuff',
'chicken' => 'cluck',
'bird' => 'tweet'
];
$keyNotStartingWithC = fn($value, $key) => $key[0] !== 'c';
echo A::find($array, $keyNotStartingWithC);
// output: 'wuff'