4 ms·
i would like to see it done more like javascript with un-named function. instead of: $replacement = function ($matches) { return str_replace ($matc
by henryw 18y ago
i would like to see it done more like javascript with un-named function. instead of:
$replacement = function ($matches) {
return str_replace ($matches[1], ' ', ' ').' ';
};
return preg_replace_callback ('/( +) /', $replacement, $text);
do:
return preg_replace_callback ('/( +) /', function ($matches) {
return str_replace ($matches[1], ' ', ' ').' ';
}, $text);
and also make array_map more like Array.each(e) in js:
$processed = array_map($array, function($e) {
return strtolower($e);
});
and all the custom defined functions like usort:
$processed = usort($array, function($a, $b) {
return $a > $b ? 1 : -1;
});
- thwarted 18y agoThose are great ideas, and with any kind of /decent/ parser and code generator would be possible (because presumably the function expression returns a function type, which can be stored in a variable or passed around). But this is in PHP, were is_* functions ONLY work on "expressions" that look like variables (not expressions that evaluate to values), and debug_backtrace, while it returns an array, can not be indexed inline without assigning the result of it to a variable first.