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<sizeof($columns);$i++){            $column = $columns[$i];        if($fill==true){            $l = ($max-sizeof($column));            for($ii=0;$ii<$l;$ii++){                array_push($column,'');            }        }        if($reverse==true){            $columns[$i] = array_reverse($column);        }else{            $columns[$i] = $column;        }    }    for($i=0,$l=sizeof($columns);$i<$l;$i++){        $column = $columns[$i];        $c.=<tr>;        for($ii=0,$ll=sizeof($column);$ii<$ll;$ii++){            $c.=<td>.$column[$ii].</td>;        }        $c.=</tr>;    }    return <table.html::attributes($attr).>.$c.</table>;}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);
PHP Table generation
php;php5
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 && sizeof($columns) < $max_cols) {            $columns = array_merge($columns, array_fill(0, $max_cols - sizeof($columns), ''));        }        if ($reverse) {            $columns = array_reverse($columns);        }        $c .= '<tr><td>' . implode('</td><td>', $columns) . '</td></tr>';    }    return '<table>' . $c . '</table>';}