I am trying to echo a string from a Recursive function:
echo "<li>", $node, recurse($arr), "</li>";
and
echo "<li>" . $node . recurse($arr) . "</li>";
function writeList($tree)
{
if($tree == null) return;
echo "<ul>";
foreach($tree as $node=>$children) {
echo "<li>", $node, writeList($children) , "</li>";
}
echo "</ul>";
}
$tree
is a tree-like structure, as can be found in this question (form2)
And, I can notice that the output from the two is different.
Can someone tell me the difference in using ,
and .
in general, and particularly, in this example?
EDIT: what if rather than echoing the strings, I want to store the string generated from this function in a variable. I am, particularly, interested in the output received from the first echo
statement.
EDIT: I am feeding this array:
array
3 =>
array
4 =>
array
7 => null
8 =>
array
9 => null
5 => null
6 => null
The outputs I am getting is:
(from first echo statement)
<ul><li>3<ul><li>4<ul><li>7</li><li>8<ul><li>9</li></ul></li></ul></li><li>5</li></ul></li><li>6</li></ul>
(from second echo statement)
<ul><ul><ul><li>7</li><ul><li>9</li></ul><li>8</li></ul><li>4</li><li>5</li></ul><li>3</li><li>6</li></ul>