3v4l.org

run code in 500+ PHP versions simultaneously
<?php //no. of ques $total_ques = 45; //creating array for que no $que_nos = range(1,(int)$total_ques); $part = 10; //splitting array in chunks $cols = array_chunk($que_nos,$part); echo '<table border="1" cellpadding="5">'; echo '<tr>'; foreach($cols as $col) { //Generating heading columns echo "<td>Q</td>"; echo "<td>Tally</td>"; echo "<td>Total</td>"; } echo '</tr>'; //data for each row $row_data = []; for ($i=0; $i < $part; $i++) { //temporary variable containing values for each row $temp_row_data = []; foreach($cols as $k1 => $col) { //getting first value of array $value = reset($col); $temp_row_data[] = $value ?: ''; if ($value !== false) { //unset value as it is already processed unset($cols[$k1][array_search($value,$col)]); } } //storing temporary array in main row array $row_data[] = $temp_row_data; } foreach ($row_data as $key => $cd) { echo '<tr>'; foreach ($cd as $c) { echo "<td>{$c}</td>"; echo "<td></td>"; echo "<td></td>"; } echo '</tr>'; } echo '</table>';

preferences:
141.3 ms | 2521 KiB | 5 Q