Voting

: max(three, zero)?
(Example: nine)

The Note You're Voting On

mail at nititech dot de
2 months ago
A simple fallback For older PHP versions, that do not have array_find:

<?php

/**
* Porting of PHP 8.4 function
*
* @template TValue of mixed
* @template TKey of array-key
*
* @param array<TKey, TValue> $array
* @param callable(TValue $value, TKey $key): bool $callback
* @return ?TValue
*
* @see https://www.php.net/manual/en/function.array-find.php
*/
function array_find(array $array, callable $callback): mixed
{
foreach (
$array as $key => $value) {
if (
$callback($value, $key)) {
return
$value;
}
}

return
null;
}
?>

<< Back to user notes page

To Top