Not much needs to be said here.
function array_map_recursive($callback, $arr) {
$ret = array();
foreach($arr as $key => $val) {
if(is_array($val)) $ret[$key] = array_map_recursive($callback, $val);
else $ret[$key] = $callback($val);
}
return $ret;
}
$ret = array();
foreach($arr as $key => $val) {
if(is_array($val)) $ret[$key] = array_map_recursive($callback, $val);
else $ret[$key] = $callback($val);
}
return $ret;
}
I wrote this so that I could do this…
$filters = array('htmlspecialchars', 'nl2br');
foreach($filters as $filter) $view_vars = array_map_recursive($filter, $view_vars);
foreach($filters as $filter) $view_vars = array_map_recursive($filter, $view_vars);
Which just sanitizes my variables before I print them.
One thought on “array_map_recursive”
thanks for post 😉
Dmitry Salnikov web developer