-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopy.php
More file actions
60 lines (53 loc) · 1.64 KB
/
loopy.php
File metadata and controls
60 lines (53 loc) · 1.64 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
for($i = 1; $i <=5; $i++){
echo str_repeat("*", $i);
echo "<br>";
}
for($i = 5; $i >0; $i--){
echo str_repeat("*", $i);
echo "<br>";
}
// for($i = 5; $i >0; $i--){
// for($j = 1; $j <=5; $j++){
// echo str_repeat("-", $i);
// echo str_repeat("*", $j);
// echo "<br>";
// }
// echo "<br>";
// }
?>
<?php
$maxRows = $_GET['maxRows'] ?? 10; //?? -> NULL-COALESCENCE
$maxCols = $_GET['maxCols'] ?? 10;
?>
<html>
<body>
<h1>Exercise 3: output asterisk (*) on every alternate columns</h1>
<table border="1" cellspacing="5" cellpadding="5">
<?php for($row = 1; $row <= $maxRows; $row++){ ?>
<tr>
<?php for($col = 1; $col <= $maxCols; $col++){
if(($row + $col) % 2 ==0){ ?>
<td>*</td>
<?php } else { ?>
<td> </td>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
<table border="1" cellspacing="5" cellpadding="5">
<?php for($row = 1; $row <= $maxRows; $row++){ ?>
<tr>
<?php for($col = 1; $col <= $maxCols; $col++){
if(($row==1 || $row == $maxRows) || ($col==1 || $col == $maxCols)){ ?>
<td>*</td>
<?php } else { ?>
<td> </td>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
</body>
</html>