Recursive Array Filtering

note to self .. a nice clean way to do recursive array filters in PHP

$arr = array(
  'teSt',
  'The quick BroWn ...',
  'foO',
  array(
    'Test sTring'
  )
);
    
$filter = function(&$input) use (&$filter) {
  if (is_array($input)) $input = array_map($filter, $input);
  else if (is_string($input)) $input = strtolower($input);
  return $input;
};
    
$filter($arr);
var_dump($arr);
comments powered by Disqus