PHP 8.4 brings several handy array utility functions that reduce the need for writing custom loops or array_filter callbacks. array_find() returns the first element matching a predicate, while array_all() checks if every element passes a condition, and array_any() checks if at least one element matches.

PHP 8.4 Example:

PHP
$users = [
    ['id' => 1, 'role' => 'editor'],
    ['id' => 2, 'role' => 'admin'],
    ['id' => 3, 'role' => 'subscriber']
];

$admin = array_find($users, fn($user) => $user['role'] === 'admin');
$hasAdmin = array_any($users, fn($user) => $user['role'] === 'admin');

var_dump($admin);    // Returns array of user 2
var_dump($hasAdmin); // bool(true)

The articles and images featured on this platform were generated with the assistance of AI tools.