Skip to content

Instantly share code, notes, and snippets.

@sikrew
Last active March 28, 2016 15:04
Show Gist options
  • Save sikrew/60fc07a875e31d073996 to your computer and use it in GitHub Desktop.
Save sikrew/60fc07a875e31d073996 to your computer and use it in GitHub Desktop.
ul li tree generator function
<?php
$tree = array(
'Parent' => array(
'Children 1' => array(
'1\'s Child 1',
'1\'s Child 2',
'1\'s Child 3'
),
'Children 2' => array(
'2\'s Child 1',
'2\'s Child 2',
'2\'s Child 3'
)
)
);
function ulLiTree($tree) {
$out = '<ul>';
foreach($tree as $key => $value) {
$out.= '<li>';
if (is_array($value)) {
$out.='<a href="#">'.$key.'</a>'.ulLiTree($value);
} else {
$out.= '<a href="#">'.$value.'</a>';
}
$out.= '</li>';
}
$out.= '</ul>';
return $out;
}
echo ulLiTree($tree);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment