I was wondering how can you generate lists that have many nested lists deep using PHP.
How would you go about coding the PHP.
I'm stumped please help I'm new to PHP.
I was wondering how can you generate lists that have many nested lists deep using PHP.
How would you go about coding the PHP.
I'm stumped please help I'm new to PHP.
Perhaps this function (print_r)
(This answers the question in the title. For the others, please consult a book/tutorial. Please use the resources available.)
Here's one method:
$tree = array(
1, 2,
array(31, 32, array(331, 332, 333)), array(341, 342),
4, array(51, 52, 53, 54, array(551, 552, 553, array(5541, 5542))),
);
render_tree($tree);
function render_tree($tree, $indent = 0) {
$space = str_repeat(' ', $indent);
echo "$space<ul>\n";
foreach ($tree as $node) {
render_node($node, $indent + 2);
}
echo "$space</ul>\n";
}
function render_node($node, $indent) {
$space = str_repeat(' ', $indent);
if (is_array($node) && count($node) > 0) {
echo "$space<li>\n";
render_tree($node, $indent + 2);
echo "$space</li>\n";
} else {
echo "$space<li>$node</li>\n";
}
}
What is the CSS code to display a nested list? What is the Dyanmic code to display nested list? What is the form processing to diplay a nested list? What is the code in Javascript to display a nested list?