The answer of @Vitor42 is ok, but if you want something more generic and you are sure that the data is always complete try with:
<table>
<?php
$info = array(
array( first_name => Stack , last_name => Overflow ),
array( first_name => Andrew , last_name => Oliveira )
);
$sHtmlHead = <tr> ;
$arrHtmlBodies = array();
$nSize = sizeOf($info);
for($i=0;$i<$nSize;$i++){
$sHtmlHead .= <th>Person .$i. </th> ;
$arrTemp = $info[$i];
$j = 0;
foreach($arrTemp as $data){
if(!isset($arrHtmlBodies[$j])) $arrHtmlBodies[$j] = <tr> ;
$arrHtmlBodies[$j] .= <td> .$data. </td> ;
if($i==($nSize-1)) $arrHtmlBodies[$j] .= </tr> ;
$j++;
}
}
echo $sHtmlHead; ?></tr>
<?php
echo implode( ,$arrHtmlBodies); ?></tr>
</table>
如果你无法确定数据是否完整:
<table>
<?php
$info = array(
array( first_name => Stack , last_name => Overflow ),
array( first_name => Andrew , last_name => Oliveira ),
array( first_name => Eli ),
array( last_name => Astocaza )
);
$sHtmlHead = <tr> ;
$arrHtmlBodies = array();
$nSize = sizeOf($info);
$arrKeys = array_keys($info[ 0 ]);
$nSizeKeys = sizeOf($arrKeys);
for($i=0;$i<$nSize;$i++){
$sHtmlHead .= <th>Person .$i. </th> ;
$arrTemp = $info[$i];
$j = 0;
for($j=0;$j<$nSizeKeys;$j++){
if(!isset($arrHtmlBodies[$j])) $arrHtmlBodies[$j] = <tr> ;
$arrHtmlBodies[$j] .= <td> .$info[$i][$arrKeys[$j]]. </td> ;
if($i==($nSize-1)) $arrHtmlBodies[$j] .= </tr> ;
}
}
echo $sHtmlHead; ?></tr>
<?php
echo implode( ,$arrHtmlBodies); ?></tr>
</table>