My Report

PHP Loops Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following PHP code?

<?php
for ($x = 1; $x < 10;++$x)
{
    print "*\t";
}
?>

2. What will be the output of the following PHP code?

<?php
$x;
for ($x = -3; $x < -5; ++$x)
{
    print ++$x;
}
?>

3. What will be the output of the following PHP code?

<?php
$i = 0;
for ($i)
{
    print $i;
}
?>

4. What will be the output of the following PHP code?

<?php
for ($i++; $i == 1; $i = 2)
    print "In for loop ";
print "After loop\n";

?>

5. What will be the output of the following PHP code?

<?php
for ($x = 0; $x <= 10; print ++$x)
{
    print ++$x;
}
?>

6. What will be the output of the following PHP code?

<?php
for (1; $i == 1; $i = 2)
    print "In for loop ";
print "After loop\n";
?>

7. What will be the output of the following PHP code?

<?php
for ($i == 2; ++$i == $i; ++$i)
    print "In for loop ";
print "After loop\n";
?>

8. What will be the output of the following PHP code?

<?php
for ($x = -1; $x < 10;--$x)
{
    print $x;
}
?>

9. What will be the output of the following PHP code?

<?php
$colors = array("red","green","blue","yellow"); 
foreach ($colors as $value)
{
    echo "$value <br>";
}
?>

10. What will be the output of the following PHP code?

<?php
for ($x = 0; $x <= 10; $x++)
{
    echo "The number is: $x <br>";
}
?>

 

Start practicing “1000 MCQs on PHP”, and once you are ready, you can take tests on all topics by attempting our “PHP Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.