Created
October 2, 2019 09:07
-
-
Save uberbrady/0b7d40141fe8f59cbc9b521a562360dd to your computer and use it in GitHub Desktop.
This file contains 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
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