Write a php program to draw a rectangle using for loop
ADVERTISEMENTS
Write a php program to draw a rectangle using for loop. There are you will learn how to draw a rectangle using for loop.
Take an example to draw this pattern through a php program:
<?php
// Write a PHP program to
// draw a rectangle using for loop
$r = 7;
$c = 9;
for ($i = 1; $i <= $r; $i++) {
for ($j = 1; $j <= $c; $j++) {
if ($i == 1 || $i == $r || $j == 1 || $j == $c)
echo "* ";
else
echo " ";
}
echo "\n";
}
?>
Output:
* * * * * * * * *
* *
* *
* *
* *
* *
* * * * * * * * *
Tags:
# write a php program to draw a rectangle without using graphics
# write a php program to print rectangle pattern of numbers
# write a php program to print the square pattern of numbers