Explore topic-wise MCQs in Php.

This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Php knowledge and support exam preparation. Choose a topic below to get started.

1.

What will be the output of the following PHP code ?
<?php
switch($k)
{
case 2:
print "First";
break;
case k:
print "Second";
break;
}
?>

A. Undefined variable: k
B. First
C. Second
D. Nothing
E. None of these
Answer» B. First
2.

What will be the output of the following PHP code ?
<?php
switch($t)
{
case 2:
print "Interview";
break;
case 1:
print "Mania";
break;
}
?>

A. Error
B. Interview
C. Interview Mania
D. Mania
E. None of these
Answer» B. Interview
3.

What will be the output of the following PHP code ?
<?php
$opt = "1";
switch($opt)
{
case 1:
break;
print "First Statement";
case 2:
print "Second Statement";
break;
default:
print "Third Statement";
}
?>

A. First Statement
B. Second Statement
C. Third Statement
D. Nothing
E. None of these
Answer» E. None of these
4.

What will be the output of the following PHP code ?
<?php
$n = 128;
switch($n)
{
case "n":
print "Welcome to";
break;
case 128:
print "Interview";
break;
default:
print "Mania";
}
?>

A. Mania
B. Error
C. Interview
D. Welcome to
E. None of these
Answer» D. Welcome to
5.

What will be the output of the following PHP code ?
<?php
$p = "1";
$p = 1;
$q = 1;
switch($p)
{
case $p * $q:
print "Hello";
break;
case $p / $q:
print "Hey";
break;
default:
print "Bye";
}
?>

A. Hello
B. Hey
C. Bye
D. Error
E. None of these
Answer» B. Hey
6.

What will be the output of the following PHP code ?
<?php
$opt = "1";
switch ($opt)
{
case 1:
print "Hello ";
case 2:
print "Interview ";
default:
print "Mania ";
}
?>

A. Hello Interview Mania
B. Interview
C. Mania
D. Hello
E. None of these
Answer» B. Interview
7.

What will be the output of the following PHP code ?
<?php
$s = 2.2;
switch($s)
{
case 2.1:
print "Option A";
break;
case 2.2:
print "Option B";
break;
default:
print "Option C";
}
?>

A. Error
B. Option A
C. Option B
D. Option C
E. None of these
Answer» D. Option C
8.

What will be the output of the following PHP code ?
<?php
const $k = 10;
switch($k)
{
case 10:
print "First";
break;
case 11:
print "Second";
break;
default:
print "Third";
}
?>

A. Third
B. Second
C. Error
D. First
E. None of these
Answer» D. First
9.

What will be the output of the following PHP code ?
<?php
$k = 1;
switch(print $k)
{
case 2:
print "Statement1";
break;
case 1:
print "Statement2";
break;
default:
print "Statement3";
}
?>

A. Error
B. Statement1
C. Statement3
D. 1Statement2
E. None of these
Answer» E. None of these