In this post we will give you information about How to Print the number triangle pattern 1 in php. Hear we will give you detail about How to make the number triangle pattern 1 in php And how to use it also give you demo for it if it is necessary.
How to make the number triangle pattern 1 in php
Program to display how to Print the number triangle pattern 1 in php using for loop.
For or Foreach loop makes program easy to iterate over number of rows.
Example 1: pattern in php
$k=1; for($i=0;$i<5;$i++){ for($j=1;$j<=$i;$j++){ echo$k." "; $k++; } echo"
"; }
Triangle Pattern Program In PHP
Example 2:
$k=1; for($i=0;$i<5;$i++){ for($j=1;$j<=$i;$j++){ echo $k." "; $k++; } echo "
"; }
Star Half Pyramid
Star Half Pyramid– Mirrored
$i+1; $k-- ) { echo " "; } for($j = 0; $j <= $i; $j++ ) { echo "* "; } echo "\n"; } } $num = 5; generateStarPtn($num); ?>
Star Half Pyramid– Inverted
0; $i--){ for($j = 0; $j < $i; $j++ ) { echo "* "; } echo "\n"; } } $num = 5; generateStarPtn($num); ?>
Star Half Pyramid– Inverted Mirrored
0; $i--) { for($k = $i; $k < $num; $k++ ) { echo " "; } for($j = 0; $j < $i; $j++ ) { echo "* "; } echo "\n"; } } $num = 5; generateStarPtn($num); ?>
Star Full Pyramid
$i+1; $k-- ) { echo " "; } for($j = 0; $j <= $i; $j++ ) { echo "* "; } echo "\n"; } } $num = 5; generateStarPtn($num); ?>
Star Diamond
$i+1; $k-- ) { echo " "; } for($j = 0; $j <= $i; $j++ ) { echo "* "; } echo "\n"; } // The Lower Half Pattern for ($i = $num-1; $i > 0; $i--) { for($k = $num-1; $k >= $i; $k-- ) { echo " "; } for($j = 0; $j < $i; $j++ ) { echo "* "; } echo "\n"; } } $num = 5; generateStarPtn($num); ?>
Hope this code and post will helped you for implement How to Print the number triangle pattern 1 in php. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs