Program & Design Tips, tricks, tutorials, and tools on programming & web design

7Jul/090

array_map_recursive

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;
}

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);

Which just sanitizes my variables before I print them.

Filed under: PHP Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.