summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-rw-r--r--it.class10
1 files changed, 5 insertions, 5 deletions
diff --git a/it.class b/it.class
index 42808ad..0f17e37 100644
--- a/it.class
+++ b/it.class
@@ -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);