Php Star Pattern Program

Most of us stuck with star pattern program, here are some of them you can practice and find the code for:-

Program for Full Pyramid Using Star

untitled2

// Outer loop for changing rows 
for ($i = 1; $i <= 5; $i++) {

 //Loop added for spacing 
 for ($j = $i; $j <= 5; $j++) {

 echo "&nbsp;&nbsp;";
 }

 //Loop to print star as needed 
 for ($k = 1; $k < ($i * 2); $k++) {
 echo "*";
 }
 echo "</br>";
}

Program For Another Star Pattern
untitled1


// Outer loop for changing rows of full pyramid
for ($i = 1; $i <= 5; $i++) {
 //Loop added for spacing 
 for ($j = $i; $j < 5; $j++) {
 echo "&nbsp;&nbsp;";
 }

 //Loop to print star as needed 
 for ($k = 1; $k < ($i * 2); $k++) {
 echo "*";
 }
 echo "</br>";
}

// Outer loop for changing rows of inverted pyramid
for ($i = 4; $i >= 1; $i--) {
 //Loop added for spacing 
 for ($j = 5; $j > $i; $j--) {
 echo "&nbsp;&nbsp;";
 }

 //Loop to print star as needed 
 for ($k = 1; $k < ($i * 2); $k++) {
 echo "*";
 }
 echo "</br>";
}

Program For Star Pattern With Space In A Rhombus

untitled3


// Outer loop for changing rows
for ($i = 1; $i <= 5; $i++) {

 //Loop added for outer spacing 
 for ($j = 5; $j > $i; $j--) {
 echo "&nbsp;&nbsp;";
 }
 echo "*";

 //Loop added for internal spacing 
 for ($j = 1; $j < ($i - 1) * 2; $j++) {
 echo "&nbsp;&nbsp;";
 }
 if ($i == 1)
 echo "</br>";
 else
 echo "*</br>";
}

// Outer loop for changing rows
for ($i = 4; $i >= 1; $i--) {

 //Loop added for outer spacing 
 for ($j = 5; $j > $i; $j--) {
 echo "&nbsp;&nbsp;";
 }
 echo "*";

 //Loop added for internal spacing 
 for ($j = 1; $j < ($i - 1) * 2; $j++) {
 echo "&nbsp;&nbsp;";
 }
 if ($i == 1)
 echo "</br>";
 else
 echo "*</br>";
}

Program For Inverted Pyramid Using Star

star_pattern

// Outer loop for changing rows
for ($i = 5; $i >= 1; $i--) {
 //Loop added for spacing 
 for ($j = 5; $j > $i; $j--) {
 echo "&nbsp;&nbsp;";
 }

 //Loop added for printing star
 for ($k = 1; $k < ($i * 2); $k++) {
 echo "*";
 }
 echo "</br>";
}

Another Star Pattern

star_pattern1


// Outer loop for changing rows
for ($i = 1; $i <= 5; $i++) {
 for ($j = 1; $j <= 6 - $i; $j++) {
 echo "*";
 }
 for ($k = 1; $k < $i; $k++) {
 echo "&nbsp;&nbsp;&nbsp;&nbsp;";
 }
 for ($j = 1; $j <= 6 - $i; $j++) {
 echo "*";
 }
 echo "</br>";
}

// Outer loop for changing rows
for ($i = 2; $i <= 5; $i++) {
 for ($j = 1; $j <= $i; $j++) {
 echo "*";
 }
 for ($k = 1; $k <= 5 - $i; $k++) {
 echo "&nbsp;&nbsp;&nbsp;&nbsp;";
 }
 for ($j = 1; $j <= $i; $j++) {
 echo "*";
 }
 echo "</br>";
}

Program For Right Angle Triangle Using Star

right1


for ($i = 1; $i <= 5; $i++) {
 for ($j = 1; $j <= $i; $j++) {
 echo "*";
 }
 echo "</br>";
}

Program For Right Angle Inverted Triangle Using Star

inverted_right1

for ($i = 5; $i >= 1; $i--) {
 for ($j = 1; $j <= $i; $j++) {
 echo "*";
 }
 echo "</br>";
}

Program For Right Angle Triangle Using Star

inverted

for ($i = 5; $i >= 1; $i--) {
 for ($j = 1; $j < $i; $j++) { echo "&nbsp;&nbsp;"; } for ($k = 5; $k >= $i; $k--) {
 echo "*";
 }
 echo "</br>";
}

Program For Right Angle Inverted Triangle Using Star

right1

for ($i = 5; $i >= 1; $i--) {
 for ($j = 5; $j > $i; $j--) {
 echo "&nbsp;&nbsp;";
 }
 for ($k = 1; $k <= $i; $k++) {
 echo "*";
 }
 echo "</br>";
}

 

Leave a Comment.