shlogg · Early preview
Paul Redmond @paulredmond

PHP 8.4 Array Helper Functions: Array_find() And More

Four new array functions are coming to PHP 8.4: array_find(), array_find_key(), array_any() and array_all(). They help check arrays for specific conditions, returning the first match or a boolean result.

Four new array functions are coming to PHP 8.4 which are helper functions for checking an array for the existence of elements matching a specific condition. The new functions are:
array_find()
array_find_key()
array_any()
array_all()
#The array_find() Function
The array_find($array, $callback) function returns the first element for which the $callback returns true:
$array = [    'a' => 'dog',    'b' => 'cat',    'c' => 'cow',    'd' => 'duck',    'e' => 'goose',    'f' => 'elephant']; array_find($array, function (string $value) {    return strlen($value) > 4;}); // string(5) "goose" array_find...