Skip to content

Instantly share code, notes, and snippets.

@sylwit
Created March 18, 2012 17:06
Show Gist options
  • Save sylwit/2077683 to your computer and use it in GitHub Desktop.
Save sylwit/2077683 to your computer and use it in GitHub Desktop.
Array_map() recursive and closure
$array_map_recursive = function ($fn, $arr) use(&$array_map_recursive) {
$rarr = array ();
foreach ( $arr as $k => $v ) {
$rarr [$k] = is_array ( $v ) ? $array_map_recursive ( $fn, $v ) : $fn ( $v ); // or call_user_func($fn, $v)
}
return $rarr;
};
ex: $ini = $array_map_recursive('htmlspecialchars_decode', $ini);
@julienw
Copy link

julienw commented Mar 20, 2012

à chaque fois qu'on fait de la récursivité, on pourrait l'écrire en itératif... avec plus de contrôle ;) (enfin, c'est que mon avis !)

@tzi
Copy link

tzi commented Mar 20, 2012

Je veux bien voir l'implémentation en itératif ! J'ai peur que ce soit moins lisible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment