Posted By

erraja_07 on 09/29/11


Tagged


Versions (?)

Code to Display Star Using PHP


 / Published in: PHP
 

  1. $c=1;
  2. $n = 9;
  3. for($i=1;$i<=$n;$i++)
  4. {
  5. for($j=$i;$j<$n;$j++)
  6. {
  7. echo "&nbsp;&nbsp;";
  8. }
  9. for($k=1;$k<=$c;$k++)
  10. {
  11. if($k%2==0)
  12. echo "&nbsp;&nbsp;";
  13. else
  14. echo '*';
  15. }
  16. echo "<br />";
  17. $c+=2;
  18. }
  19. for($i=$n;$i>=1;$i--)
  20. {
  21. for($j=$i;$j<$n;$j++)
  22. {
  23. echo "&nbsp;&nbsp;";
  24. }
  25. for($k=$c-1;$k>1;$k--)
  26. {
  27. if($k%2==0)
  28. echo "&nbsp;&nbsp;";
  29. else
  30. echo '*';
  31. }
  32. echo "<br />";
  33. $c-=2;
  34. }

Report this snippet  

You need to login to post a comment.