diff options
author | Urban Müller | 2016-08-26 15:30:40 +0200 |
---|---|---|
committer | Urban Müller | 2016-11-10 16:00:50 +0100 |
commit | 665cf76c34f910504705bbb24da1498709d69960 (patch) | |
tree | 2caf4bdbc8d708e94d9c93e17dacdd473f52ef7e /it.class | |
parent | 52aa39b034da27fc758f0ae5a78c0b5ace05e295 (diff) | |
download | itools-665cf76c34f910504705bbb24da1498709d69960.tar.gz itools-665cf76c34f910504705bbb24da1498709d69960.tar.bz2 itools-665cf76c34f910504705bbb24da1498709d69960.zip |
it:map(): allow any callable object (anon functions) or code in string
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -938,16 +938,16 @@ static function date($format = "", $stamp = null) } /** - * Iterate over an array, replacing every element by expression - * @param $expression The expression to apply, may contain $k for keys and $v for values + * Iterate over an array, replacing every element by function value or expression + * @param $code The function or expression to apply. Expression may contain $k for keys and $v for values * @param $array The array to iterate over */ -static function map($expression, $array) +static function map($code, $array) { static $cache = array(); - if (!($func = $cache[$expression])) - $func = $cache[$expression] = create_function('$k,$v', "return $expression;"); + if (!is_callable($func = $code) && !($func = $cache[$code])) + $func = $cache[$code] = create_function('$k,$v', "return $code;"); foreach ($array as $k => $v) $result[$k] = $func($k, $v); |