Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
Created October 17, 2017 19:23
Show Gist options
  • Select an option

  • Save rogersguedes/69bb1c59b6556dbb184d6a4282e5cf71 to your computer and use it in GitHub Desktop.

Select an option

Save rogersguedes/69bb1c59b6556dbb184d6a4282e5cf71 to your computer and use it in GitHub Desktop.
<?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