I have this trimmer
function, it recursively trims all values in array (people put tons of spaces for no reason!):
function trimmer(&$var) {
if (is_array($var)) {
foreach($var as &$v) {
trimmer($v);
}
}
else {
$var = trim($var);
}
}
trimer($_POST);
PROBLEM: I would like to add new feature: i want this function also to convert all _
(underscore) in keys to spaces. I know how to convert keys (str_replace('_', ' ', $key)
), but i have trouble to make it work in this recursive style...
Input:
$_POST['Neat_key'] = ' dirty value ';
Expected result:
$_POST['Neat key'] = 'dirty value';