mburt
09-25-2011, 03:17 AM
Given:
function table($array) {
foreach ($array as $x) {
if (is_array($x)) {
table($x);
} else echo "<div class=\"table_cell\">$x</div>\n";
} echo "<div class=\"clear\"></div>\n";
}
table(
array(
array("1", "2"),
array("3", "4")
)
);
I don't understand why it produces:
<div class="table_cell">1</div>
<div class="table_cell">2</div>
<div class="clear"></div>
<div class="table_cell">3</div>
<div class="table_cell">4</div>
<div class="clear"></div>
<div class="clear"></div>
I've tried to run through this recursive function mentally but I just can't seem to understand why it produces an extra div.
What I'm trying to do, is write:
<div class="clear"></div> at the end of each sub-array.
Any thoughts anyone?
function table($array) {
foreach ($array as $x) {
if (is_array($x)) {
table($x);
} else echo "<div class=\"table_cell\">$x</div>\n";
} echo "<div class=\"clear\"></div>\n";
}
table(
array(
array("1", "2"),
array("3", "4")
)
);
I don't understand why it produces:
<div class="table_cell">1</div>
<div class="table_cell">2</div>
<div class="clear"></div>
<div class="table_cell">3</div>
<div class="table_cell">4</div>
<div class="clear"></div>
<div class="clear"></div>
I've tried to run through this recursive function mentally but I just can't seem to understand why it produces an extra div.
What I'm trying to do, is write:
<div class="clear"></div> at the end of each sub-array.
Any thoughts anyone?