Examveda
Examveda

What will be the output of the following PHP code ?
<?php
function A1($x)
{
  switch($x)
  {
  case 1: 
    //this statement is the same as if($x == 1)
    echo 'Case 1 was executed.';
    break;
  case 2: 
    //this statement is the same as if($x == 2)
    echo 'Case 2 was executed.';
    break;
  case 3: 
    //this statement is the same as if($x == 3)
    echo 'Case 3 was executed.';
    break;
  case 4: 
    //this statement is the same as if($x == 4)
    echo 'Case 4 was executed.';
    break;
  default: 
    //this statement is the same as if $x does not equal the other conditions
    echo 'Default was executed.';
    break;
  }
}
A1(9);
?>

A. Case 1 was executed

B. Case 2 was executed

C. Default was executed

D. Case 4 was executed

Answer: Option D

Solution(By Examveda Team)

The switch statement is executed with $x = 9.

This Question Belongs to PHP >> Functions

Join The Discussion

Comments ( 2 )

  1. CS VN
    CS VN :
    3 years ago

    opton c is correct, not D!

  2. Andrew Lviv
    Andrew Lviv :
    4 years ago

    correct answer is - Default was executed.

Related Questions on Functions