In this tutorial, i am going to share how to print triangle of character pattern in PHP with the output.
Create new PHP file and copy paste below code to execute and print the character pattern using PHP.
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 |
<?php function alphapat($n) { // initializing value corresponding to 'A' $num = 65; // outer loop to handle number of rows for ($i = 0; $i < $n; $i++) { // inner loop to handle // number of columns values changing acc. for ($j = 0; $j <= $i; $j++ ) { // explicitly converting to char $ch = chr($num); // printing char value echo $ch." "; } // incrementing number $num = $num + 1; // ending line after each row echo "\n"; } } // Driver Code $n = 5; alphapat($n); ?> |
A
B B
C C C
D D D D
E E E E E
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.