Skip to content

Instantly share code, notes, and snippets.

@uberbrady
Created October 2, 2019 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uberbrady/0b7d40141fe8f59cbc9b521a562360dd to your computer and use it in GitHub Desktop.
Save uberbrady/0b7d40141fe8f59cbc9b521a562360dd to your computer and use it in GitHub Desktop.
function indenter($locations, $parent_id = null, $prefix = '') {
$results = Array();
foreach($locations as $location) {
if($location->parent_id == $parent_id) {
//append this parent node first,
$location->use_text = $prefix.' '.$location->name
$results[] = $location;
//now append the children.
$results = array_merge($results,indenter($locations,$location->id,$prefix.'--'));
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment