In these tutorials, you will learn to print the star pattern program in PHP, patterns like a half pyramid, full pyramid, etc.
<?php
function star_pattern($row){
for ($i = 1; $i <= $row; $i++)
{
for ($j = 1; $j <= $i; $j++)
{
echo " * ";
}
echo "\n";
}
}
$row=5;
star_pattern($row);
?>
* * * * * * * * * * * * * * *
<?php
function star_pattern($row){
for ($i = $row; $i >= 1; $i--)
{
for ($j = 1; $j <= $i; $j++)
{
echo " * ";
}
echo "\n";
}
}
$row=6;
star_pattern($row);
?>
* * * * * * * * * * * * * * * * * * * * *
<?php
function star_pattern($row){
$k = 0;
for ($i = 1; $i <= $row; $i++, $k = 0)
{
for ($space = 1; $space <= $row - $i; $space++)
{
echo " ";
}
while ($k != 2 * $i - 1) {
echo("* ");
$k++;
}
echo "\n";
}
}
$row=6;
star_pattern($row);
?>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
<?php
function star_pattern($row){
$k = 0;
for ($i = $row; $i >= 1; $i--, $k = 0)
{
for ($space = 0; $space < $row - $i; $space++)
{
echo " ";
}
for ($j = $i; $j <= 2 * $i - 1; $j++)
{
echo " * ";
}
for ($j = 0; $j < $i - 1; $j++)
{
echo " * ";
}
echo "\n";
}
}
$row=6;
star_pattern($row);
?>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *