<?php
Class Table{
Var $Table_Array=array();
Var $Headers=array();
Var $Cols;
Function Table($Headers){
$this->Headers=$Headers;
$this->Cols=count($Headers);
}
Function addRow($row){
If(count($row) != $this->Cols)
return false;
Array_push($this->Table_Array, $row);
return true;
}
Function addRowAssocArray($row_assoc){
$row=array();
foreach($this->Headers as $Header){
If( ! isset($row_assoc[$Header]))
$row_assoc[$Header]=" ";
$row[]=$row_assoc[$Header];
}
Array_push($this->Table_Array, $row);
return true;
}
Function output(){
Echo"<pre>";
foreach($this->Headers as $Header)
echo"<font size=\"2\">$Header</font> ";
Echo"\n";
foreach($this->Table_Array as $y){
foreach($y as $xcell)
echo"$xcell ";
Echo"\n";
}
echo"</pre>";
}
}
$test=New Table(array("a","b","c"));
$test->addRow(array(1,2,3));
$test->addRow(array(4,5,6));
$test->addRowAssocArray(array(b=>5, a=>6, c=>3));
$test->output();
?>
I was wondering if someone could perhaps explain :
Function addRowAssocArray($row_assoc){
$row=array();
foreach($this->Headers as $Header){
If( ! isset($row_assoc[$Header]))
$row_assoc[$Header]=" ";
$row[]=$row_assoc[$Header];
}
Array_push($this->Table_Array, $row);
return true;
}
This in more detail? I understand that it arranges the numbers in order of the A,B,C but Im not quite sure how it does it? and what the values of row_assoc is in this "$row_assoc[$header]= " ";