Answers for "Mapping, Filtering and Reducing in PHP"

PHP
0

Mapping, Filtering and Reducing in PHP

function getNames(array $users, $excludeId)
{
    $filtered = array_filter($users, function ($u) use ($excludeId) {
        return $u['id'] != $excludeId;
    });

    return array_map(function ($u) { return $u['name']; }, $filtered);
}
Posted by: Guest on October-04-2021

Browse Popular Code Answers by Language