Monday, March 23, 2015

Diamond Pattern in PHP

In this article I would like to share with you a code that I wrote using PHP to display an image of an diamond using asterisk. The code is very short and easy to understand I'm just using for loop statement to create the diamond image.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





Program Listing

<html>
<title> Diamond Pattern </title>
<body bgcolor="lightgreen">
<h1><font face="comic sans ms" color="red"> Diamond Pattern in PHP </face></h1>
<?php

$a=6; $b=0; $c=0; $space = 1;
  $space = $a - 1;
  for ($c = 1; $c <= $a; $c++)
  {
    for ($b = 1; $b <= $space; $b++)
    echo " &nbsp;&nbsp;&nbsp;   ";

     for ($b = 1; $b <= 2*$c-1; $b++)
     printf("<font size='6' color='red'> * </font> ");
     printf("<br>");
     $space=$space-1;
  }
  $space = 1;
  for ($c = 1; $c <= $a - 1; $c++)
  {
    for ($b = 1; $b <= $space; $b++){
     echo " &nbsp;&nbsp;&nbsp;  ";
     }
    $space++;
    for ($b = 1 ; $b <= 2*($a-$c)-1; $b++) {
      printf("<font size='6' color='red'> * </font> ");
 }
     echo "<br>";
  }
  ?>
 </body>
 </html>
  

No comments:

Post a Comment