belongs to collection: PHP Programs
Some different alphabet triangle patterns using range() function in PHP are shown below.
Pattern 1
<?php $alpha = range('A', 'Z'); for($i=0; $i<5; $i++){ for($j=5; $j>$i; $j--){ echo $alpha[$i]; } echo "<br>"; } ?>
Output:
Pattern 2
<?php $alpha = range('A', 'Z'); for($i=0; $i<5; $i++){ for($j=0; $j<=$i; $j++){ echo $alpha[$i]; } echo "<br>"; } ?>
Pattern 3
<?php $alpha = range('A', 'Z'); for($i=0; $i<5; $i++){ for($j=0; $j<=$i; $j++){ echo $alpha[$j]; } echo "<br>"; } ?>
Pattern 4
<?php $alpha = range('A', 'Z'); for($i=0; $i<5; $i++){ for($j=4; $j>=$i; $j--){ echo $alpha[$j]; } echo "<br>"; } ?>
Pattern 5
<?php $alpha = range('A', 'Z'); for ($i=5; $i>=1; $i--) { for($j=0; $j<=$i; $j++) { echo ' '; } $j--; for ($k=0; $k<=(5-$j); $k++) { echo $alpha[$k]; } echo "<br>\n"; } ?>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Pattern 1
Output:
Pattern 2
Output:
Pattern 3
Output:
Pattern 4
Output:
Pattern 5
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer