- array_chunk: documentation ( source)
- implode: documentation ( source)
- array_fill: documentation ( source)
<?php
$word = "cat";
$q = 13;
$row_max = 5;
$words = array_fill(0, $q, $word);
$chunks = array_chunk($words, $row_max);
foreach ($chunks as $chunk) {
echo '<tr><td>' . implode('</td><td>', $chunk) . '</td></tr>' . "\n";
}