Are you looking to how to write a PHP program to print pyramid pattern formed of stars? Use the following PHP code to print pyramid pattern.
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 | /** * Write a PHP program to print pyramid pattern. */ function pattern($n) { // For printing the upper part of the pyramid for ($i = 1; $i < $n; $i++) { for ($j = 1; $j < $i+1; $j++) { echo " * "; } echo "\n" ; } // For printing the lower part of pyramid for ($i = $n; $i > 0; $i--) { for ($j = $i; $j > 0; $j--) { echo " * "; } echo "\n" ; } } // Driver code $n=6; pattern($n); |
Program Output
1 2 3 4 5 6 7 8 9 10 11 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.