How To Make The Star Triangle In Php?

It is very easy to make a STAR Triangle in php. This is a type of matrix in which we can print rows and columns. You can make the STAR triangle by using (for loop) or (foreach) loop in php. ‘For’ or ‘foreach’ loop make it very easy in to make STAR Triangle. This can improve the logic of Fresher. Check below the programming syntax in front of output:

* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
<?php
for($i=0;$i<=5;$i++){
for($j=5-$i;$j>=1;$j--){
echo "*&nbsp;";
}
echo "<br>";
}
?>
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
</pre>
<?php
for($i=0;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "*&nbsp;";
}
echo "<br>";
}
?>
 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
<?php for($i=0;$i=$i;$k--){
echo " ";
}
for($j=1;$j<=$i;$j++){
echo "*"." ";
}
echo "<br>";
}?>
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
<?php

for($i=5;$i-->=0;$i--){
for($k=5;$k>=$i;$k--){
echo "  ";
}
for($j=1;$j<=$i;$j++){
echo "*  ";
}
echo "<br>";
}
?>
 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
<?php
for($i=0;$i<=6;$i++){
for($k=6;$k>=$i;$k--){
echo " &nbsp;";
}
for($j=1;$j<=$i;$j++){
echo "* &nbsp;";
}
echo "<br>";
}
for($i=5;$i>=1;$i--){
for($k=6;$k>=$i;$k--){
echo " &nbsp;";
}
for($j=1;$j<=$i;$j++){
echo "* &nbsp;";
}
echo "<br>";
}
?>
53 Comments

Leave a Reply