Dinesh Uprety
@dineshuprety ·
Public
Find the first matching array value
PHPPHP 8.4 tip: use array_find() instead of a manual search loop. Source: php.net/releases/8.4
PHP
CodeSnap // free canvas
Find the first matching array value
<?php
$admin = array_find(
$users,
static fn (User $user): bool => $user->isAdmin(),
);
// $admin is the first match, or null.