How can I display a 2 dimensonal array?
The question is kind of vague. It really depends on your data, what it represents.
Most likely you WANT to display it as a TABLE . with one key being column head the other rows.
For example, if you are using PHP:
<table ><?
// $twoDarray is your array
function renderTDs( $cells, $tag='td',$rhead=true,$row=false) {
$firstTD=true;
foreach ( $cells as $cont){
if ($rhead && $firstTD){echo '<th>',$row,"</th>\
";}
echo "<$tag>",$cont,"</$tag>\
";
$firstTD=false;
}
}
function renderTable( $twoDarray, $rhead=true,$chead=true) {
if ($chead){
echo '<thead>';
if ($rhead){echo '<th></th>';}
$ths=array_keys($twoDarray);
$ths=array_keys($twoDarray[$ths[0]]);
renderTDs($ths, $tag='th',false);
echo "</thead>\
";
}
foreach ( $twoDarray as $row=>$cells){
echo '<tr>';
renderTDs($cells,'td',$rhead,$row);
echo "<tr>\
";
}
}
$twoDarray['row1']['col1']=1;
$twoDarray['row1']['col2']=1;
$twoDarray['row1']['col3']=1;
$twoDarray['row1']['col4']=1;
$twoDarray['row2']['col1']=1;
$twoDarray['row2']['col2']=1;
$twoDarray['row2']['col3']=1;
$twoDarray['row2']['col4']=1;
renderTable($twoDarray);
?>
</table>
(hastily put together as am on the phone with a client)
$twoDarray is YOUR array.
if you want a table with column and row heads : renderTable($twoDarray);
if you want a table with column heads : renderTable($twoDarray,false);
if you want a table with row heads, but no col head : renderTable($twoDarray,true,false);
if you want a table with no heads : renderTable($twoDarray,false,false);
hope that helps
As @dresden_phoenix; said, the question is vague and hard to answer precisely for that very reason. Being specific pays off, I can assure you.
Dresden has given you an example in PHP but… is this the language you need?