Use a foreach loop and an array_fill for the empty cells
// Set the names array.
$names = array("Mike", "Kyle", "Johnny", "Will", "Vasques");
// Set the table cell start key.
$table_cell_start_key = 0;
// Set the table cell count.
$table_cell_count = 9;
// Set the table cells.
$table_cells = implode("", array_fill($table_cell_start_key, $table_cell_count, '<td></td>'));
// Loop through the names array & echo output.
foreach($names as $name) {
echo "<tr>"
. "<td>$name</td>"
. $table_cells
. "</tr>"
;
}
The nice thing about using an array_fill
is you can simple set the values for $table_cells
ahead of the foreach
loop. And then the foreach
loop is just to render content based on the $names
and the extra table cells are just dropped in.