Last active
November 20, 2021 03:44
-
-
Save viniciusmelocodes/45f99eace3491b028c3baecc4b2a0b91 to your computer and use it in GitHub Desktop.
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
function buildTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) { | |
foreach ($array as $categoryId => $category) { | |
if ($currentParent == $category['parent_id']) { | |
if ($currLevel > $prevLevel) echo "<ol id='menutree'>"; | |
if ($currLevel == $prevLevel) echo "</li>"; | |
echo '<li> <label class="menu_label" for='.$categoryId.'>'.$category['name'].'</label><input type="checkbox" id='.$categoryId.' />'; | |
if ($currLevel > $prevLevel) { $prevLevel = $currLevel; } | |
$currLevel++; | |
buildTree ($array, $categoryId, $currLevel, $prevLevel); | |
$currLevel--; | |
} | |
} | |
if ($currLevel == $prevLevel) echo "</li> </ol>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment