Jump to content

Recommended Posts

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

 

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

[][][][][][][][][][][][][][][][][][][][]

Link to comment
https://forums.phpfreaks.com/topic/185407-for-loop/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978782
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978791
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/185407-for-loop/#findComment-978792
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.