Home > Backend Development > PHP Tutorial > Implement a star array with a specified number of rows

Implement a star array with a specified number of rows

WBOY
Release: 2016-07-25 08:47:20
Original
1885 people have browsed it
Loop output algorithm exercise
  1. if(!empty($_GET['row'])){
  2. $row=$_GET['row'];
  3. }else {
  4. $row=10;
  5. }
  6. echo '

    Direct left triangle

    ';
  7. for($i=0;$i<$row;$i++){
  8. for($j=0;$j<=$i;$ j++){
  9. echo '*';
  10. }
  11. echo '
    ';
  12. }
  13. echo '

    right right triangle

    ';
  14. for($i=0;$i< ;$row;$i++){
  15. for($j=$row-1;$j>$i;$j--){
  16. echo ' ';
  17. }
  18. for($j=0;$j< =$i;$j++){
  19. echo '*';
  20. }
  21. echo '
    ';
  22. }
  23. echo '

    Parallelogram

    ';
  24. for($i=0 ;$i<$row;$i++){
  25. for($j=$row-1;$j>$i;$j--){
  26. echo ' ';
  27. }
  28. for($j=0; $j<=$row;$j++){
  29. echo '*';
  30. }
  31. echo '
    ';
  32. }
  33. echo '

    Isosceles Triangle

    ';
  34. for( $i=1;$i<$row+1;$i++){
  35. for($j=$row;$j>$i;$j--){
  36. echo ' ';
  37. }
  38. for($ j=1;$j<=2*$i-1;$j++){
  39. echo '*';
  40. }
  41. echo '
    ';
  42. }
  43. echo '

    Inverted Isosceles Triangle

    ';
  44. for($i=$row;$i>0;$i--){
  45. for($j=0;$j<=$row-$i-1;$j++) {
  46. echo ' ';
  47. }
  48. for($j=1;$j<=2*$i-1;$j++){
  49. echo '*';
  50. }
  51. echo '
    ';
  52. }
  53. echo '

    Rhombus

    ';
  54. function rhomb($row){
  55. for($i=1;$i<$row+1;$i++){
  56. for($ j=$row;$j>$i;$j--){
  57. echo ' ';
  58. }
  59. for($j=1;$j<=2*$i-1;$j++){
  60. echo '*';
  61. }
  62. echo '
    ';
  63. }
  64. for($i=$row;$i>0;$i--){
  65. for($j=0;$j<= $row-$i-1;$j++){
  66. echo ' ';
  67. }
  68. for($j=1;$j<=2*$i-1;$j++){
  69. echo '*';
  70. }
  71. echo '
    ';
  72. }
  73. }
  74. rhomb($row/2);
  75. ?>
Copy code
Implement a star array with a specified number of rows


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template