I have a MySQL table with a tree data structure. The fields are _id, name and parentId. When the record hasn\'t a parent, parent
Pass a parameter to count the iteration like $pass
function toUL ($arr, $pass = 0) {
$html = '' . PHP_EOL;
foreach ( $arr as $v ) {
$html.= '- ';
$html .= str_repeat("--", $pass); // use the $pass value to create the --
$html .= $v['name'] . '
' . PHP_EOL;
if ( array_key_exists('children', $v) ) {
$html.= toUL($v['children'], $pass+1);
}
}
$html.= '
' . PHP_EOL;
return $html;
}