PHP

PHP

For Loops has 27 Questions
What will be the output of the following PHP code ?
  1. <?php
  2. $i = 0;
  3. for ($i)
  4. {
  5.     print $i;
  6. }
  7. ?>

0
infinite loop
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. $colors = array("red","green","blue","yellow"); 
  3. foreach ($colors as $value)
  4. {
  5.     echo "$value<br>";
  6. }
  7. ?>

ed

green

blue

yellow

red
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. for ($x = 0; $x <= 10; $x++)
  3. {
  4.     echo "The number is: $x<br>";
  5. }
  6. ?>

he number is: 0

The number is: 1

The number is: 2

The number is: 3

The number is: 4

The number is: 5

The number is: 6

The number is: 7

The number is: 8

The number is: 9

The number is: 10

The number is: 0
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. for ($x = 0; $x <= 10; print ++$x)
  3. {
  4.     print ++$x;
  5. }
  6. ?>

123456789101112
12345678910
1234567891011
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. for ($x = 1; $x < 10;++$x)
  3. {
  4.     print "*\t";
  5. }
  6. ?>

**********
*********
***********
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. for ($x = -1; $x < 10;--$x)
  3. {
  4.     print $x;
  5. }
  6. ?>

123456789101112
12345678910
1234567891011
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. $x;
  3. for ($x = -3; $x < -5; ++$x)
  4. {
  5.     print ++$x;
  6. }
  7. ?>

-3-4-5
-3-4
infinite loop
no output
What will be the output of the following PHP code ?
  1. <?php
  2. for (1; $i == 1; $i = 2)
  3.     print "In for loop ";
  4. print "After loop\n";
  5. ?>

In for loop
After for loop
In for loopAfter for loop
infinite loop
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i == 2; ++$i == $i; ++$i)
  3.     print "In for loop ";
  4. print "After loop\n";
  5. ?>

In for loopIn for loopIn for loopIn for loop......infinitely
After for loopAfter for loopAfter for loop........infinitely
In for loopAfter for loopIn for loopAfter for loopIn for loopAfter for loop.....infinitely
After for loop
What will be the output of the following PHP code ?
  1. <?php
  2. for ($x = 1; $x < 10; $x++)
  3.     for ($y = 1; $y < 5; $y++)
  4.         print "Hello";
  5. ?>

Hello....36 times
Hello....45 times
Hello....50 times
Hello....40 times
What will be the output of the following PHP code ?
  1. <?php
  2. for ($count = 1; $count != 20;$count++)
  3. {
  4.     print $count;
  5.     $count++;
  6. }
  7. ?>

Infinite
123.......20
1357...19
13579...21
What will be the output of the following PHP code ?
  1. <?php
  2. for ($count = 1; $count < 20; $count++);
  3.     print $count;
  4. ?>

20
19
12345678910....19
12345678910....1920
What will be the output of the following PHP code ?
  1. <?php
  2. for ($count = 0; $count < 3;$count++);
  3. {
  4.     print "hi";continue;print "hello";
  5. }
  6. ?>

hihihi
hihellohihellohihello
hellohellohello
hi
What will be the output of the following PHP code ?
  1. <?php
  2. for ($count = 0; $count<3;$count++);
  3. {
  4.     print "hi";break;print "hello";
  5. }
  6. ?>

hihihi
hihellohihellohihello
hellohellohello
hi
What will be the output of the following PHP code ?
  1. <?php
  2. for(++$i; ++$i; ++$i)
  3. {
  4.     print $i;
  5.     if ($i == 4) 
  6.         break;
  7. }
  8. ?>

24
134
1234
1
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0;$i = -1;$i = 1)
  3. {
  4.     print $i;
  5.     if ($i != 1) 
  6. 	break;
  7. }
  8. ?>

0
infinite loop
-1
1
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; $i < 3; $i++)
  3. {
  4.     for($j = $i; $j > 0; $j--)
  5.         print " ";
  6.     for($k = $j; $k < 3; $k++)
  7.         print "*";
  8. 	print "\n";  
  9. }
  10. ?>

*

**

***

***

**

*

* ** ***
error
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; -5 ; $i++)
  3. {
  4.     print"i";
  5.     if ($i == 3)
  6.         break;
  7. }
  8. ?>

0 1 2 3 4
0 1 2 3
0 1 2 3 4 5
error
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; 0; $i++) {
  3.     print"i";
  4. }
  5. ?>

infinite loop
0
no output
error
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; $i < 5; $i++) {
  3.     for ($j = $i; $j > 0; $i--)
  4.         print $i;
  5. }
  6. ?>

infinite loop
0 1 2 3 4 5
0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5
no output
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; $i < 5; $i++)  {
  3.     for ($j = $i;$j > $i; $i--)
  4.         print $i;
  5. }
  6. ?>

infinite loop
0 1 2 3 4 5
0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5
no output
What will be the output of the following PHP code ?
  1. <?php
  2. $user = array("Ashley", "Bale", "Shrek", "Blank");
  3. for ($x = 0; $x < count($user); $x++) {
  4.     if ($user[$x] == "Shrek") 
  5. 	    continue;
  6.     printf ($user[$x]); 
  7. }
  8. ?>

AshleyBaleBlank
AshleyBale
AshleyBaleShrek
no output
What will be the output of the following PHP code ?
  1. <?php
  2. $user = array("Ashley", "Bale", "Shrek", "Blank");
  3.     for ($x=0; $x < count($user) - 1; $x++)	{
  4.         if ($user[$x++] == "Shrek") 
  5. 		    continue;
  6.         printf ($user[$x]); 
  7.     }
  8. ?>

AshleyBaleBlank
Bale
AshleyShrek
BaleBlank
What will be the output of the following PHP code ?
  1. <?php
  2. $user = array("Ashley", "Bale", "Shrek", "Blank");
  3. for ($x = 0; $x < count($user); $x) {
  4.     if ($user[$x++] == "Shrek") 
  5. 	    continue;
  6.     printf ($user[$x]); 
  7. }
  8. ?>

AshleyBaleBlank
BaleShrek
AshleyBlank
Bale
What will be the output of the following PHP code ?
  1. <?php
  2. for ($i = 0; $i % ++$i; $i++) {
  3.     print"i";
  4. }
  5. ?>

error
infinite loop
no output
0
What will be the output of the following PHP code ?
  1. <?php
  2. $a = array("hi", "hello", "bye");
  3. foreach ($a as $value) {
  4.     if (count($a) == 2)
  5. 	    print $value;         
  6. }
  7. }
  8. ?>

hihellobye
infinite loop
hihello
no output
What will be the output of the following PHP code ?
  1. <?php
  2. $a = array("hi", "hello", "bye");
  3. for (;count($a) < 5;) {
  4.     if (count($a) == 3)
  5. 	    print $a;         
  6. }
  7. ?>

ArrayArrayArrayArrayArrayArray....infinitely
("hi"?,"?hello"?,"?bye"?)("hi"?,"?hello"?,"?bye"?)("hi"?,"?hello"?,"?bye"?)("hi"?,"?hello"?,"?bye"?)...infinitely
hihellobyehihellobyehihellobyehihellobyehihellobyehihellobye.....infinitely
no output