0% found this document useful (0 votes)
13 views4 pages

PHP Prac 3

The document contains PHP programs demonstrating different types of loops: a for loop that increments by 5 up to 100, a while loop that counts from 1 to 10, a do-while loop that starts at 5 and counts to 10, and a foreach loop that iterates through an array of numbers and an associative array of names and ages.

Uploaded by

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

PHP Prac 3

The document contains PHP programs demonstrating different types of loops: a for loop that increments by 5 up to 100, a while loop that counts from 1 to 10, a do-while loop that starts at 5 and counts to 10, and a foreach loop that iterates through an array of numbers and an associative array of names and ages.

Uploaded by

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

Practical No.

3
1) Write a php program to implement for loop.
<?php

for ($num = 1; $num<= 100; $num += 5)

echo $num . " <br> ";

?>
2) Write a php program to implement while loop.

<?php

$num = 1;

while ($num<= 10) {

echo $num . " <br> ";

$num++;

?>
3) Write a php program to implement do-while loop.

<?php

$num = 5;

do {

echo $num . " ";

$num++;

} while ($num<= 10);

?>
4) Write a program to implement for each loop.

<?php

$a = array (10, 20, 30, 40, 50, 60);

foreach ($a as $val)

echo $val . " ";

echo "\n";

echo "<br>";

$ages = array( "Saee" => 18, "Anjali" => 19, "Shreya" => 18);

foreach ($ages as $name => $age)

echo $name . " => " . $age . "\n";

?>

You might also like