All pastes #188520 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-10-02 06:41 UTC
rendered paste body
<?php

function tablify( $rows, $colsPerRow, $data )
{
  $string = "<table>\n";
  $string .= "<tr>\n";
  for( $i = 0; $i < $rows; $i++ )
  {
    for( $j = 0; $j < $colsPerRow; $j++ )
    {
      $string .= "<td>".$data[$i][$j]."</td>\n";
    }
    if( $j % $colsPerRow == 0 && ($i !== $rows - 1) )
    {
      $string .= "</tr><tr>\n";
    }
  }
  $string .= "</tr>\n";
  $string .= "</table>\n";
  return $string;
}

$array = array();

$array[0][0] = "test00";
$array[0][1] = "test01";
$array[0][2] = "test02";

$array[1][0] = "test10";
$array[1][1] = "test11";
$array[1][2] = "test12";

$array[2][0] = "test20";
$array[2][1] = "test21";
$array[2][2] = "test22";

echo tablify( 3, 3, $array );