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

Code:
<?php
$car = "Honda";

switch ($car) {
    case "Honda":
        echo "You selected Honda.";
    case "BMW":
        echo "You selected BMW.";
    case "AUDI":
        echo "You selected Audi.";
    default:
        echo "None is selected.";
}
?>
  • (A) You selected Honda.
  • (B) You selected Honda.You selected BMW.
  • (C) You selected Honda.You selected BMW.You selected Audi.
  • (D) You selected Honda.You selected BMW.You selected Audi.None is selected.
πŸ’¬ Discuss
βœ… Correct Answer: (D) You selected Honda.You selected BMW.You selected Audi.None is selected.

Q. How many loops are there in PHP?

  • (A) 2
  • (B) 3
  • (C) 4
  • (D) 5
πŸ’¬ Discuss
βœ… Correct Answer: (C) 4

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

Code:
<?php
$counter = 1;

while ($counter++ <= 5)
{
    echo $counter, ",";
    $counter++;
}
?>  
  • (A) 2,4
  • (B) 1,2,3,4,5,
  • (C) 2,4,6
  • (D) 1,2,4,
πŸ’¬ Discuss
βœ… Correct Answer: (C) 2,4,6

Q. Which loop statement is used to loop through a block of code a specified number of times?

  • (A) while
  • (B) do...while
  • (C) for
  • (D) foreach
πŸ’¬ Discuss
βœ… Correct Answer: (C) for

Q. Which loop statement is used to loop through a block of code for each element in an array?

  • (A) while
  • (B) do...while
  • (C) for
  • (D) foreach
πŸ’¬ Discuss
βœ… Correct Answer: (D) foreach

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

Code:
<?php
$cars = array(
    "BMW",
    "Mercedes",
    "Honda",
);

foreach ($cars as $c)
{
    echo "$c ";
}
?>
  • (A) BMW Mercedes Honda
  • (B) Honda Mercedes BMW
  • (C) SyntaxError
  • (D) TypeError
πŸ’¬ Discuss
βœ… Correct Answer: (A) BMW Mercedes Honda

Q. Which PHP statement is used to jump out of a loop?

  • (A) exit
  • (B) break
  • (C) continue
  • (D) stop
πŸ’¬ Discuss
βœ… Correct Answer: (B) break

Q. What is the use of PHP "continue" statement?

  • (A) breaks the loop and transfers the control to the statement written just after the loop body
  • (B) breaks the all loop statement (outer loops and inner loops)
  • (C) breaks one iteration of the loop and transfers the control to the next loop iteration
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) breaks one iteration of the loop and transfers the control to the next loop iteration

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

Code:
<?php
for ($i = 1;$i <= 10;$i++){
    if ($i == 6){
        continue;
    }
    echo "$i ";
}
?>
  • (A) 1 2 3 4 5 7 8 9 10
  • (B) 1 2 3 4 5 6 7 8 9 10
  • (C) 1 2 3 4 5 6
  • (D) 1 2 3 4 5
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1 2 3 4 5 7 8 9 10

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

Code:
<?php  
$x = 10; 
  
while ($x < 10) { 
    $x++;
    echo $x, ","; 
} 
?>
  • (A) Infinite loop
  • (B) Error
  • (C) 10, 11,
  • (D) No output
πŸ’¬ Discuss
βœ… Correct Answer: (D) No output