The following code is used to dynamically generate the table that you have shown. You can change the values of $array1, $array2 or $array3 respectively and table is generate dynamically.
<?php
$array1 = array('A','B','C');
$array2 = array('S','C','M');
$array3 = array('A1','B1','C1','D1','E1','F1');
/* Get the length of all arrays */
$lengthArray1 = count($array1);
$lengthArray2 = count($array2);
$lengthArray3 = count($array3);
?>
<table border="1" width="50%">
<thead>
<!-- Print the header -->
<tr>
<!-- For first empty space -->
<td></td>
<?php
/* Based on the length of the array display the headers */
for($i = 0; $i < $lengthArray1; $i++){ ?>
<!-- Align center and add the colspan wrt to $array length -->
<td colspan="<?php echo $lengthArray2; ?>" align="center">
<?php echo $array1[$i]; ?>
</td>
<?php
} ?>
</tr>
<tr>
<!-- For first empty space -->
<td></td>
<?php
/* Loop through all the $array1 so that that many $array2 values will be assigned to $array1 header */
for($i = 0; $i < $lengthArray1; $i++){
for($j = 0; $j < $lengthArray2; $j++){
?>
<td align="center">
<?php echo $array2[$j]; ?>
</td>
<?php
}
} ?>
</tr>
</thead>
<tbody>
<!-- Loop through $array3 -->
<?php
for($i = 0; $i < $lengthArray3; $i++){ ?>
<tr>
<!-- Print $array3 value in first td -->
<td><?php echo $array3[$i]; ?></td>
<?php
/* To get the remaining td's I have multiplied $array1 X $array2 */
for($j = 0; $j < ($lengthArray1 * $lengthArray2); $j++){
?>
<td></td>
<?php
}
?>
</tr>
<?php
} ?>
</tbody>
</table>