Created
March 12, 2015 09:25
-
-
Save zmiftah/efa1e054eb63d2f09b7c to your computer and use it in GitHub Desktop.
How to Create Treelike Structure
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
protected function traverseData($programs, $parentId=0) | |
{ | |
$data = array(); | |
foreach ($programs as $id => $program) { | |
if ($program['parent'] == $parentId) { | |
$nodes = $this->traverseData($programs, $program['id']); | |
$obj = new StdClass; | |
$obj->text = $program['name']; | |
$obj->icon = 'fa fa-file'; | |
$obj->href = '#program-'.$program['id']; | |
if ($nodes) { $obj->nodes = $nodes; } | |
$data[] = $obj; | |
} | |
} | |
return $data; | |
} |
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
Result: | |
[ | |
{ | |
"text":"SEN", | |
"icon":"fa fa-file", | |
"href":"#program-54", | |
"nodes": | |
[ | |
{ | |
... | |
} | |
] | |
}, | |
... | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment