PHP Table generation I have been using the following function (in the kohana html class in a table) to generate tables.

function table($columns,$reverse=false,$fill=false,array $attr=null){
    $c = '';
    //ugly hack, looking for fix
    $max=sizeof(max($columns));
    for($i=0;$i&lt;sizeof($columns);$i++){
            $column = $columns[$i];

        if($fill==true){
            $l = ($max-sizeof($column));
            for($ii=0;$ii&lt;$l;$ii++){
                array_push($column,'');
            }
        }
        if($reverse==true){
            $columns[$i] = array_reverse($column);
        }else{
            $columns[$i] = $column;
        }
    }
    for($i=0,$l=sizeof($columns);$i&lt;$l;$i++){
        $column = $columns[$i];
        $c.="&lt;tr&gt;";
        for($ii=0,$ll=sizeof($column);$ii&lt;$ll;$ii++){
            $c.="&lt;td&gt;".$column[$ii]."&lt;/td&gt;";
        }
        $c.="&lt;/tr&gt;";
    }
    return "&lt;table".html::attributes($attr)."&gt;".$c."&lt;/table&gt;";
}


And then I have been calling it like so:

echo html::table(array(
    array('colunm 1 row 1','colunm 2 row 1'),
));


And a reversed table that auto fills the columns.

echo html::table(array(
    array('colunm 1 row 1','colunm 2 row 1'),
    array('column 1 row 2','column 2 row 2')
),true,true);
Didn't test, but I would write it something like this:

function table($rows, $reverse = false, $fill = false, array $attr = null) {
    $c = '';
    $max_cols = sizeof(max($columns));

    foreach ($rows as $columns) {
        if ($fill &amp;&amp; sizeof($columns) &lt; $max_cols) {
            $columns = array_merge($columns, array_fill(0, $max_cols - sizeof($columns), ''));
        }
        if ($reverse) {
            $columns = array_reverse($columns);
        }
        $c .= '&lt;tr&gt;&lt;td&gt;' . implode('&lt;/td&gt;&lt;td&gt;', $columns) . '&lt;/td&gt;&lt;/tr&gt;';
    }

    return '&lt;table&gt;' . $c . '&lt;/table&gt;';
}