Print star pattern in PHP

In this post we will give you information about How to Print the number triangle pattern 1 in php. Hear we will give you detail about How to make the number triangle pattern 1 in php And how to use it also give you demo for it if it is necessary.

How to make the number triangle pattern 1 in php

Program to display how to Print the number triangle pattern 1 in php using for loop.
For or Foreach loop makes program easy to iterate over number of rows.

Triangle Pattern Program In PHP
Triangle Pattern Program In PHP

Example 1: pattern in php

$k=1;
for($i=0;$i<5;$i++){
    for($j=1;$j<=$i;$j++){
        echo$k." ";
        $k++;
    }
    echo"<br>";
}

Triangle Pattern Program In PHP

Example 2:

$k=1;

for($i=0;$i<5;$i++){

	for($j=1;$j<=$i;$j++){
		echo $k." ";
		$k++;
	}
	echo "<br>";
} 

Star Half Pyramid

<?php
function generateStarPtn($num)
{

for ($i = 0; $i < $num; $i++)
{

for($j = 0; $j <= $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Star Half Pyramid– Mirrored

<?php
function generateStarPtn($num)
{

for ($i = 0; $i < $num; $i++)
{

for($k = $num; $k > $i+1; $k-- )
{

echo "  ";
}

for($j = 0; $j <= $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Star Half Pyramid– Inverted

<?php
function generateStarPtn($num)
{

for ($i = $num; $i > 0; $i--){

for($j = 0; $j < $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Star Half Pyramid– Inverted Mirrored

<?php
function generateStarPtn($num)
{

for ($i = $num; $i > 0; $i--)
{

for($k = $i; $k < $num; $k++ )
{

echo "  ";
}

for($j = 0; $j < $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Star Full Pyramid

<?php
function generateStarPtn($num)
{

for ($i = 0; $i < $num; $i++)
{

for($k = $num; $k > $i+1; $k-- )
{

echo " ";
}

for($j = 0; $j <= $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Star Diamond

<?php
function generateStarPtn($num)
{


for ($i = 0; $i < $num; $i++)
{

for($k = $num; $k > $i+1; $k-- )
{

echo " ";
}

for($j = 0; $j <= $i; $j++ )
{

echo "* ";
}

echo "\n";
}
// The Lower Half Pattern

for ($i = $num-1; $i > 0; $i--)
{

for($k = $num-1; $k >= $i; $k-- )
{

echo " ";
}

for($j = 0; $j < $i; $j++ )
{

echo "* ";
}

echo "\n";
}
}

$num = 5;
generateStarPtn($num);
?>

Hope this code and post will helped you for implement How to Print the number triangle pattern 1 in php. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs