Created
October 17, 2017 19:23
-
-
Save rogersguedes/69bb1c59b6556dbb184d6a4282e5cf71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function array_traverse (&$array, $function, $limit=2, $truncate=true) { | |
| foreach ($array as $key => &$value) { | |
| if (is_array($value)) { | |
| if ($limit > 0) { | |
| array_traverse($value, $function, --$limit, $truncate); | |
| } else { | |
| if ($truncate) { | |
| $value = '{truncated}'; | |
| } | |
| } | |
| } else { | |
| $value = $function($value, $key); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment