Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace core\utils;
- /**
- * Loops over an array, calls expression on each its element and collects results into new array.
- * @param mixed $array
- * @param callback $expression Expression function taking $key and $value parameters.
- * @return array
- */
- function yeld($array, $expression)
- {
- $result = array();
- foreach($array as $key => $value)
- $result[$key] = $expression($key, $value);
- return $result;
- }
- /**
- * Joins all elements of $array with applying formatter and using separator string.
- * @param mixed $array
- * @param callback $formatter
- * @param string $separator
- * @return string
- */
- function joinFormatted($array, $separator, $formatter)
- {
- return implode($separator, yeld($array, function($key, $value)use($formatter) { return $formatter($key, $value); }));
- }
Add Comment
Please, Sign In to add comment