How to print a star pattern in PHP?

Today, We want to share with you star pattern in php.In this post we will show you number pattern programs in php, hear for PHP programs for printing pyramid patterns we will give you demo and example for implement.In this post, we will learn about PHP Nested Forloop – Exercises Pyramid Program Solution with an example.

All star pattern programs in PHP

Number pattern stars in PHP can be printed using for and foreach loop. There are a some of patterns in stars pattern. Some of them are display here.

you will learn about the process to print star pattern in PHP.

Print Triangle of Stars in PHP

=$no;$k--)
{
echo "  ";
}
for($x=1;$x<=$no;$x++)
{
echo "*  ";
}
echo "
"; } for($no=5;$no>=1;$no--) { for($k=6;$k>=$no;$k--) { echo " "; } for($x=1;$x<=$no;$x++) { echo "* "; } echo "
"; } ?>

Results:

	
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Example 2: Print Star Pattern in PHP

 3 ? 6 - $xdk : $xdk); $col++)
    {
        echo '* ';
    }

     echo "
"; } ?>

Results:

*
* *
* * *
* *
*

Example 3: Print Triangle of Stars in PHP

=1; $a--)
{
if($a%2 != 0)
{
for($b=5; $b>=$a; $b--)
{
echo "* ";
}
echo "
"; } } for($a=2; $a<=5; $a++) { if($a%2 != 0) { for($b=5; $b>=$a; $b--) { echo "* "; } echo "
"; } } ?>

Results:

*
* * *
* * * * *
* * *
* 

Example 4: Print Star Pattern in PHP

=1;$x--)
{
echo "* ";
}
echo "
"; } ?>

Results:

* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Example 5: Print Star Pattern in PHP

";
}

?>

Results:

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *

Example 6: Print Triangle of Stars in PHP

";
}

?>

Results:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

Example 7:

";
}

?>

Results:

*
*
*
*
*

I hope you get an idea about PHP for loop – Exercises, Practice, Solution.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment