PHP 8 · Strings and arrays
Transform and filter arrays
Map and filter, then reindex the result.
$names = array_map(fn ($u) => $u['name'], $users);
$adults = array_values(array_filter($users, fn ($u) => $u['age'] >= 18));
PHP 8 · Strings and arrays
Map and filter, then reindex the result.
$names = array_map(fn ($u) => $u['name'], $users);
$adults = array_values(array_filter($users, fn ($u) => $u['age'] >= 18));
Was this page helpful?