Created
November 19, 2019 06:31
-
-
Save dwihujianto/16eae8c1bdc53ccabe171e2eac7e86b4 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
<?php | |
function transform_tree($categories) { | |
$data = []; | |
foreach($categories as $key => $category) { | |
$data[$key] = [ | |
'name' = $category->name | |
]; | |
if ($category->children) { | |
$data[$key]['children'] = transform_tree($category->children); | |
} | |
if ($category->audio) { | |
$data[$key]['downloadable'] = true; | |
$data[$key]['audio'] = $category->audio; | |
} | |
} | |
return $data; | |
} | |
// build | |
$trees = build_tree($categories); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment