PHP program to print Triangle number in reverse pattern

1. Program to print Triangle number in reverse pattern

```<?php
for(\$i=6;\$i>=1;\$i--)
{
for(\$j=\$i;\$j>=1;\$j--)
{
echo \$j." ";
if(\$j==1)
{
echo " ";
echo "<br />";
}
}
}
?>```

Output:

```6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
```

2. Program to print Triangle number in reverse pattern

```<?php
for(\$i=1;\$i<=6;\$i++)
{
for(\$j=\$i;\$j>=1;\$j--)
{ echo \$j." ";
if(\$j==1)
{
echo " ";
echo "<br />";
}
}
}
?>
```

Output:

```1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
```
1. Tanvi Parekh says

33333
6666
999
1212
15

give this pattern.

1. Full Stack developer says

Hello Tanvi Parekh,

```<?php
\$num = 3;
for (\$i = 1; \$i <= 6; \$i++) {
for (\$j = 6 - \$i; \$j >= 1; \$j--) {
echo \$i * \$num . " ";
}
echo "<br>";
}
?>
```
2. vishal says

Hello sir,
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13

give me this pattern ans.

1. Full Stack developer says

Hello Vishal,

Try this code –

```\$k = 1;
for (\$i = 1; \$i <= 4; \$i++) {
if (\$i % 2 == 0) { // check here row start with even number
\$h = 4 * \$i;
for (\$j = 1; \$j <= 4; \$j++) {
echo \$h.' ';
\$h--;
\$k++;
}
echo "<br>";
} else {
for (\$j = 1; \$j <= 4; \$j++) {
echo \$k.' ';
\$k++;
}
echo "<br>";
}
}
```
3. siva says

hello sir
6,1,1,1,1,1
2,4,2,2,2,2
1,1,6,1,1,1
2,2,2,4,2,2
1,1,1,1,6,1
2,2,2,2,2,4
give me this pattern ans.

1. siva says
```<?php
for (\$i = 1; \$i<= 6; \$i++) {
for (\$j = 1; \$j<= 6; \$j++) {
if(\$i%2 == 0){
if(\$i == \$j){
echo "4";
} else {
echo "2";
}
} else {
if(\$i == \$j){
echo "6";
} else {
echo "1";
}

}
}
echo "<br>";
}
?>
```
1. Vikas Kumar says

Dear Siva,
Thank you so much for the useful solution.