Class it:

/**
 * Iterate over an array, replacing every element by function value or expression
 * @param $code The function (gets val or key,val depending on argcount) or string expression ($k and $v are set) to apply. Returns new val
 * @param $array The array to iterate over
 * @param $p['keys'] Only modify elements with given keys (keys can be array or comma separated)
 */
static function map($code, $array, $p = null)
{
    $func = self::createfunc($code);
    $result = is_array($array) ? $array : iterator_to_array($array);
    foreach (isset($p['keys']) ? it::filter_keys($result, $p['keys']) : $result as $k => $v)
        $result[$k] = $func($k, $v);

    return (array)$result;
}