0% found this document useful (0 votes)
4 views

Php pr3

The document contains two PHP programs. The first program uses a for loop with an if condition to print even numbers from 1 to 10. The second program displays a pyramid pattern using nested for loops for both incrementing and decrementing rows.

Uploaded by

thopteayush604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Php pr3

The document contains two PHP programs. The first program uses a for loop with an if condition to print even numbers from 1 to 10. The second program displays a pyramid pattern using nested for loops for both incrementing and decrementing rows.

Uploaded by

thopteayush604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Write any program using if Condition with for Loop

<?php
for ($i = 1; $i <= 10;
$i++)
{
if ($i % 2 == 0)
{
echo "$i even\n"
}
}
?>

Output:
2 is even
4 is even
6 is even
8 is even
10 s even

2. Display Pyramid Pattern Using Increment/Decrement

<?php
$n = 5;
for ($i = 1; $i <= $n; $i++)
{
for ($j = 1; $j <= $n - $i; $j++)
{
echo " ";
}
for ($k = 1; $k <= (2 * $i - 1); $k++)
{
echo "*";
}
echo "\n";
}
for ($i = $n - 1; $i >= 1; $i--)
{
for ($j = 1; $j <= $n - $i; $j++)
{
echo " ";
}
for ($k = 1; $k <= (2 * $i - 1); $k++)
{
echo "*";
}

echo "\n";
}
?>

Output:

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

You might also like