jkewlo Posted December 16, 2009 Share Posted December 16, 2009 hey this is retarted i have tired everything in the world i cant seem to figure it out I am trying to make a table show like this but I cant for the life of me [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] [][][][][][][][][][][][][][][][][][][][] Quote Link to comment https://forums.phpfreaks.com/topic/185407-for-loop/ Share on other sites More sharing options...
Daniel0 Posted December 16, 2009 Share Posted December 16, 2009 $rows = 10; $cols = 10; for ($i = 0; $i < $rows; ++$i) { for ($j = 0; $j < $cols; ++$j) { echo '[]'; } echo PHP_EOL; } // OR for ($i = 0; $i < $rows; ++$i) { echo str_repeat('[]', $cols) . PHP_EOL; } // OR for ($i = 0; $i < $rows * $cols; ++$i) { echo '[]'; if ($rows % $cols == 0) { echo PHP_EOL; } } Neither of them tested, but the principles still apply. Quote Link to comment https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978782 Share on other sites More sharing options...
jkewlo Posted December 16, 2009 Author Share Posted December 16, 2009 ok tight now how will I go about doing this with a table? Quote Link to comment https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978787 Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 Before the loops output an opening table tag, at the start of the row loop output a tr opening tag, at the start of the column loop output an opening td tag then your content then a closing td tag, after the column loop at the end of the row loop output a closing tv tag, after the row loop output a closing table tag. Quote Link to comment https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978791 Share on other sites More sharing options...
Daniel0 Posted December 16, 2009 Share Posted December 16, 2009 Well, it's the same principle (you'd probably want to use the first approach). The inner for loop is for every cell, and the outer for loop does something on each row. Assuming you mean an HTML table, something like this: <table> <?php $rows = 10; $cols = 10; for ($i = 0; $i < $rows; ++$i) { echo '<tr>'; for ($j = 0; $j < $cols; ++$j) { echo "<td>{$i},{$j}</td>"; } echo '</tr>'; } ?></table> Again, untested. Quote Link to comment https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.