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>";
}
?>

Related posts:

Categories: PHP

39 Responses so far.


  1. Jack says:

    Good Article for learner. Great help. Thanks

  2. How To Make The Star Triangle In Php?| .powerfaq.com | Power FAQ

  3. Laxman SIngh says:

    How to make following star pattern in php???

    *
    * *
    * * *
    * * * *
    * * * * *
    * * * *
    * * *
    * *
    *

    • Mac says:

      < ?php for($i=0;$i<=4;$i++){ for($k=4;$k>=$i;$k–){
      echo ”  “;
      }
      for($j=1;$j< =$i;$j++){ echo "*  "; } echo "
      “;
      }
      for($i=3;$i>=1;$i–){
      for($k=4;$k>=$i;$k–){
      echo ”  “;
      }
      for($j=1;$j< =$i;$j++){ echo "*  "; } echo "
      “;
      }
      ?>

      Please try above code, Hope you will enjoy!!!

  4. ram says:

    *
    *
    * *
    * *
    * * *
    * *
    * *
    *
    *

  5. POO says:

    *
    * * *
    * * * * *
    * * * * * * *
    * * * * * * * * *

  6. How to make that
    1
    121
    12321
    1234321

  7. Haris says:

    How can we print this pattern in php.
    – – – – * * * * – – – –
    – – – * * * * * * – – –
    – – * * * * * * * * – –
    – * * * * * * * * * * –
    – – * * * * * * * * – –
    – – – * * * * * * – – –
    – – – – * * * * – – – –

  8. sunny says:

    **********
    **** ****
    *** ***
    ** **
    * *

  9. abdul says:

    How can we print this pattern in php.

    555555555
    5555555
    55555
    555
    5

    5
    555
    55555
    5555555
    555555555

  10. Ravi Kumar says:

    1 2
    3 4
    5 6
    7 8
    9 10

    plz send me code for ths using for loop

    • Mac says:

      Please try this code
      < ?php for($a=1; $a<=10; $a++){ if($a%2 != 0){ echo $a; } for($b=$a+1; $b>$a; $b–){
      if($b%2 == 0){
      echo $b;
      echo “<br>”;
      }
      }
      }
      ?>

  11. sumeet says:

    * * * * * * * * * * * * * * *
    * * * * * * * * * * * * *
    * * * * * * * * * * *
    * * * * * * * * *
    * * * * * * *
    * * * * *
    * * *
    *

  12. khetesh kumawat says:

    How can we print this pattern in php.
    input type value and then digits add and with answer

    1 =1
    1+2=3
    1+2+3=6
    1+2+3+4=10
    1+2+3+4+5=15
    …………………..
    ………………….
    the end 99 value valid

    please help me
    thanks sir

  13. shams says:

    how can we print like this pattern in php
    1*
    **2
    3***
    ****4
    5*****
    1***23*******45*****

    • Mac says:

      Please use following code
      < ?php for($a=1; $a<=5; $a++){ if($a%2 != 0){ echo $a; for($b=1; $b<=$a; $b++){ echo '*'; } } else{ for($b=1; $b<=$a; $b++){ echo '*'; } echo $a; } echo "<br>"; } for($a=1; $a<=5; $a++){ if($a%2 != 0){ echo $a; for($b=1; $b<=$a; $b++){ echo '*'; } } else{ for($b=1; $b<=$a; $b++){ echo '*'; } echo $a; } } ?>

  14. Mohit jakasaniya says:

    1
    21
    321
    4321

    • Mac says:

      Please use following code
      < ?php for($a=1; $a<=5; $a++){ for($b=$a; $b>=1; $b–){
      echo “$b”;}
      echo “<br>”;
      }
      ?>

  15. Celebspot says:

    How to print
    1
    21
    321
    4321

    • Mac says:

      Please try this code
      < ?php for($a=1; $a<=5; $a++){ for($b=$a; $b>=1; $b–){
      echo “$b”;}
      echo “<br>”;
      }
      ?>

  16. umar kakangi says:

    How can I print this pattern in php.



    —-
    —–
    ——
    ——–
    ———-

    and
    |\
    | \
    | \
    | \
    | \
    | _ _ _ \

  17. Pawan says:

    How to print this pattern
    *
    ***
    *****
    ***
    *

    • Mac says:

      Please try following code
      < ?php $s="*"; for($a=5; $a>=1; $a–){
      if($a%2 != 0){
      for($b=5; $b>=$a; $b–){
      echo $s;}
      echo “<br>”;
      }
      }
      for($a=2; $a< =5; $a++){ if($a%2 != 0){ for($b=5; $b>=$a; $b–){
      echo $s;}
      echo “<br>”;
      }
      }
      ?>

  18. tabarul says:

    How to print ??
    5
    54
    543
    5432
    54321

    • Mac says:

      Please try following code
      < ?php for($a=5; $a>=1; $a–){
      for($b=5; $b>=$a; $b–){
      echo $b;}
      echo “<br>”;
      }
      ?>

  19. Mohamad says:

    How to print it?
    ***************************************
    ******************* *******************
    ******************   ******************
    *****************     *****************
    ****************       ****************
    ***************         ***************
    **************           **************
    *************             *************
    ************               ************
    ***********                 ***********
    **********                   **********
    *********                     *********
    ********                       ********
    *******                         *******
    ******                           ******
    *****                             *****
    ****                               ****
    ***                                 ***
    **                                   **
    ***************************************

    • Mac says:

      Please use following code
      < ?php $s="*"; for($b=1; $b<=20; $b++){ for($c=20; $c>=1; $c–){
      if($c>=$b){
      echo $s;
      }
      elseif($b< =19){ echo "  "; } else{ echo $s; } } for($d=1; $d<=20; $d++){ if($b==20){ echo $s; } elseif($d<$b){ echo " "; } else{ echo $s; } } echo "<br>"; } ?>

  20. Ashish Tomar says:

    How to create this?

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    ***********

  21. Pari says:

    +
    ++
    +++
    ++++
    +++++

  22. *
    * *
    * * *
    * * * *
    * * * * *
    * * * * * *

  23. Ram says:

    How to print

    6 5 4
    3 2
    1

Leave a Reply