In this program, I will let you know the simple process to draw number pyramid in PHP using for loop.
PHP for loop execute a block of code for specified number of times.
Using for or foreach loop to draw/make number pyramid is much easier.
I am using for loop to draw/make number pyramid because of it is easier to understand that how many rows i have to iterate.
Number Pyramid
- for($i=0;$i<=9;$i++){
- for ($d=10-$i; $d > 0; $d--) {
- echo " ";
- }
- for($j=1;$j<=$i;$j++){
- echo " ".$i." ";
- }
- echo "<br>";
- }