PHP 8.4.24 Released!

Voting

: min(nine, two)?
(Example: nine)

The Note You're Voting On

miken32 at example dot com
10 months ago
This can be a replacement for array_filter() where an existence check is the only purpose. But, unlike array_filter(), the callback always requires two arguments. There's no way to change this, so some a lot of old-fashioned string callables are no longer usable.

<?php
$arr = [45, 'abc', 'def', 'ghi'];

if (array_filter($arr, 'is_integer')) {
    // works because of loose comparison: [45] == true
}

if (array_any($arr, 'is_integer')) {
    // PHP Warning:  Uncaught ArgumentCountError: is_integer() expects exactly 1 argument, 2 given
}
?>

<< Back to user notes page

To Top