tags:

views:

120

answers:

5

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.

+3  A: 

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.)

pst
*Technically* that answers any question of the form "How do I display _______ using PHP?" But I doubt that's the answer the OP is seeking (though, who knows!).
James McNellis
+3  A: 

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";
  }
}
cletus
A: 

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?

Karen
A: 

what symbol does CSS translate "id" to?

Karen
I need to know the symbol it is translated to?
Karen
A: 

Can you tell me the "symbol" to use to translate the "id" to in CSS?

Karen