html5andphp: Square Pattern In Php

Monday, 24 June 2013

Square Pattern In Php

                          Making of square pattern using php

The given squire pattern is made from loop .There are four type of loop in php 
1. for loop
2.while loop
3. do while loop
4. foreach loop 
I will tell you about loop in next post .use this code make square pattern.

Html code

<html>
<head></head>

<body>

<br><br><br><br>
<?php
$a=6;
for ( $b = 1 ; $b <= 6 ; $b++ )
{
 echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
 for ( $c = 1 ; $c <= $a ; $c++ )
   { 
    echo"&nbsp ";//using for blank space
   }
    $a--;
      for ( $c = 1 ; $c <= 2*$b - 1 ; $c++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 $w=1;
 for ( $d=6;$d>=1;$d-- )
{
  echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
for ( $e=1;$e<=$w;$e++ )
   { 
    echo"&nbsp ";
   }
    $w++;
      for ( $e=1;$e<=2*$d-1;$e++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 echo"uk";
?>
</body>
</html>

Note:
Save this code using .php extention.






For more on php visit php-tutorial
                                   
                                                        square pattern
square

No comments: