php const ROWS 10 numbers array for ROWS if numbers str_repeat ROWS fo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
const ROWS = 10;
$s = '';
$numbers = array();
for ($i = 0; $i < ROWS; ++$i) {
if($i == 0)
$numbers[] = str_repeat('1', ROWS);
for ($j = 0; $j < ROWS; ++$j)
$s .= ($j == $i) ? '2' : '1';
$numbers[] = $s;
$s = '';
}
for ($i = 0; $i < ROWS; ++$i) {
if($i == 0)
$numbers[] = str_repeat('2', ROWS);
for ($j = 0; $j < ROWS; ++$j)
$s .= ($j == $i) ? '1' : '2';
$numbers[] = $s;
$s = '';
}
echo 'Number of pages ', count($numbers);
foreach($numbers as $number){
echo '<table border="1">';
foreach(str_split($number) as $num){
echo '<tr>';
echo '<td>';
if($num == 1)
echo $num;
echo '</td>';
echo '<td>';
if($num == 2)
echo $num;
echo '</td>';
echo '</tr>';
}
echo '<hr>';
echo '</table>';
}