A couple of days ago, I made a post similar to this one.
I continued my work, but went back to this exercise after.
I need 2 more patterns in a table. The last 2 tables, I did with nested For-loops, which worked excellent, but now I'm stuck again.
What I need:
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
What I tried:
<table>
<b>Patroon III</b>
<?php
$rows = 6;
for($row = 1; $row <= $rows; $row++){
echo "<tr>";
for($col = 6; $col >= $row; $col--){
if($col <= $row){
echo "<td class='td2'>" . $col . "</td>";
}
else {
echo "<td class='td2'>" . " " . "</td>";
}
}
echo "</tr>";
}
?>
</table>
What I get:
1
2
3
4
5
6
And the second table I need:
1 2 3 4 5 6
2 3 4 5 6
3 4 5 6
4 5 6
5 6
6
What I tried:
<table>
<b>Patroon IV</b>
<?php
$rows = 6;
for($row = 1; $row <= $rows; $row++){
echo "<tr>";
for($col = 1; $col <= $row; $col++){
if($col >= $row){
echo "<td class='td2'>" . $col . "</td>";
}
else {
echo "<td class='td2'>" . " " . "</td>";
}
}
echo "</tr>";
}
?>
</table>
What I get:
1
2
3
4
5
6
Any suggestions? I'm thinking about another nested for-loop, but I don't know where to start. Not sure if the if-else statement is needed.