How to convert an array to a html table
<p>Can someone help me with this array that I have? I want to create a table that is a maximum of 5 columns and a maximum of 15 rows. If there are only 4 rows, for example, then only 4 rows should be shown instead of the 15. If there are only 3 cells that have data then the the remaining 2 should be padded with <code>$nbsp;</code>.</p>

<p>Here is my sample array:</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [name] =&gt; test1
            [item_id] =&gt; 1
        )
    [1] =&gt; Array
        (
            [name] =&gt; test2
            [item_id] =&gt; 2
        )
    [2] =&gt; Array
        (
            [name] =&gt; test3
            [item_id] =&gt; 3
        )
    [3] =&gt; Array
        (
            [name] =&gt; test4
            [item_id] =&gt; 4
        )
    [4] =&gt; Array
        (
            [name] =&gt; test5
            [item_id] =&gt; 5
        )
    [5] =&gt; Array
        (
            [name] =&gt; test6
            [item_id] =&gt; 6
        )
)
</code></pre>

<hr>

<p>My data repeats if there is a new row added. This is my issue at present.</p>

<pre><code>$row = count( $array ) / 5;
$col = 5;

echo'&lt;table border="1" width="700"&gt;';

for( $i = 0; $i &lt; $row; $i++ )
{
    echo'&lt;tr&gt;';
    for( $j = 0; $j &lt; $col; $j++ ) {
        if( ! empty( $array[$j] ) ) {
            echo '&lt;td&gt;'.$array[$j]['item_id'].'&lt;/td&gt;';
        }
    }
    echo'&lt;/tr&gt;';
}

echo'&lt;/table&gt;';
</code></pre>
