Welcome Guest, Not a member yet? Register   Sign In
Making tables
#3

[eluser]Pascal Kriete[/eluser]
Here's a little helper based on gtech's code.
Code:
function make_table($arr, $cols = 3)
{
    $rem = count($arr) % $cols;
    $out = '';
    
    if($rem != 0)
    {
        $arr = array_pad($arr, count($arr) + $cols - $rem, '-');
    }
    
    $out .= '<table border=1>';
    foreach($arr as $key => $val)
    {
        if ($key % $cols == 0)
            $out .= '<tr>'."\n";
            
        $out .= '<td>'.$val.'</td>'."\n";
        
        if ($key % $cols == $cols - 1)
            $out .= '</tr>'."\n";
    }
    return  $out.'</tr></table>';
}


Messages In This Thread
Making tables - by El Forum - 06-15-2008, 04:09 PM
Making tables - by El Forum - 06-15-2008, 07:14 PM
Making tables - by El Forum - 06-15-2008, 08:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB