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

Code:
<?php
$t = 0;
while ((--$t > ++$t) - 1)
{   
    print $t;
}
?>
  • (A) Error
  • (B) 000000000........infinite time
  • (C) 1111111.......infinite time
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (B) 000000000........infinite time

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

Code:
<?php
$num = 0;
while (++$num && --$num)
{   
    print $num;
}
?>
  • (A) 0
  • (B) Error
  • (C) 0123457........infinite time
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (C) 0123457........infinite time

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

Code:
<?php
$n = 1;
while(++$n || --$n)
{   
    print $n;
}
?>
  • (A) 2345678......infinite time
  • (B) 12345678...........infinite time
  • (C) Error
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (A) 2345678......infinite time
Explanation: As it is || operator the second expression is not evaluated and n is always incremented, in the first case to 1.

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

Code:
<?php
$p = 5;
while($p = 20)
{   
    print "INDIA";
}
print "USA";
?>
  • (A) 5
  • (B) 20
  • (C) USA
  • (D) INDIA.....infinite time
πŸ’¬ Discuss
βœ… Correct Answer: (D) INDIA.....infinite time
Explanation: While condition always gives 1.

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

Code:
<?php
$s = "";
while ($s = 20)
{   
    print "Hello";
}
print "World";
?>
  • (A) Nothing
  • (B) 20
  • (C) Hello.....infinite time
  • (D) World.....infinite time
πŸ’¬ Discuss
βœ… Correct Answer: (C) Hello.....infinite time

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

Code:
<?php
$p = 10;
while (--$p > 0)
{   
    $p++; 
    print $p; 
    print "INDIA";
}
?>
  • (A) Error
  • (B) 10
  • (C) 0
  • (D) 10INDIA......infinite time
πŸ’¬ Discuss
βœ… Correct Answer: (D) 10INDIA......infinite time

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

Code:
<?php
$k = 15;
while (--$k > 0 && ++$k)
{   
    print $k;
}
?>
  • (A) Error
  • (B) 15
  • (C) Nothing
  • (D) 15..........Infinite time
πŸ’¬ Discuss
βœ… Correct Answer: (D) 15..........Infinite time

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

Code:
<?php
$m = 8;
while (--$m > 0 || ++$m)
{   
    print $m;
}
?>
  • (A) Error
  • (B) 76546211111........infinite time
  • (C) 8
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (B) 76546211111........infinite time
Explanation: As it is || operator the second expression is not evaluated till m becomes 1 then it goes into a loop.

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

Code:
<?php
$t = 0;
while($t < 5)
{
    $t++;
print "Ajit ";
}
?>
  • (A) Ajit
  • (B) Ajit Ajit
  • (C) Ajit Ajit Ajit
  • (D) Ajit Ajit Ajit Ajit Ajit
πŸ’¬ Discuss
βœ… Correct Answer: (D) Ajit Ajit Ajit Ajit Ajit
Explanation: The while loop ends only when condition will false.

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

Code:
<?php
$n = "";
while($n)
{   
    print "Manjesh";
}
print "Ojha";
?>
  • (A) Manjesh
  • (B) Ojha
  • (C) Error
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (B) Ojha