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));

Official PHP 8 documentation

More strings and arrays commands

All strings and arrays commands · PHP 8 cheatsheet

Was this page helpful?