Great example @Typo !
You could also look into using array_walk_recursive. Consider the following:
<?php
function _clean(&$value) {
$value = htmlspecialchars($value);
}
$a = array(
1 => '<script />',
2 => '<div bla="bla&bla2=morebla"',
3 => array(
1 => '<script />',
2 => '<div bla="bla&bla2=morebla"',
),
);
array_walk_recursive($a, '_clean');
printf('<pre>%s</pre>', print_r($a, 1));
?>
This route makes things a bit easier if you need add more data cleaning methods :)