- array_slice: documentation ( source)
- implode: documentation ( source)
- range: documentation ( source)
<?php
class FooTable
{
public function getTable()
{
$table_cells = range(1, 100);
$table = $this->chunk($table_cells, 10);
foreach ($table as $row) {
echo implode(' | ', $row) . PHP_EOL;
}
}
public function chunk(array $array, $chunk_size)
{
$index = 0;
while ($index < count($array)) {
yield array_slice($array, $index, $chunk_size, true);
$index += $chunk_size;
}
}
}
$foo = new FooTable;
echo $foo->getTable();