Explore topic-wise MCQs in Php.

This section includes 26 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
$name = array("Neha", "Sumi", "Abhay");
for (;count($name) < 5;)
{
if (count($name) == 3)
print $name;
}
?>

A. Error
B. Nothing
C. Neha
D. Abhay
E. Sumi
Answer» B. Nothing
2.

What will be the output of the following PHP code ?
<?php
$arr = array("Hello", "Interview", "Mania");
foreach ($arr as $val)
{
if (count($arr) == 2)
print $val;
}
?>

A. Nothing
B. Error
C. HelloInterviewMania
D. InterviewHelloMania
E. None of these
Answer» E. None of these
3.

What will be the output of the following PHP code ?
<?php
for ($g = 0; $g % ++$g; $g++)
{
print"g";
}
?>

A. 0
B. Error
C. Nothing
D. g
E. None of these
Answer» D. g
4.

What will be the output of the following PHP code ?
<?php
for ($c = 4; $c < 9; $c++)
{
for(; $c < 9; $c++)
print"c";
}
?>

A. c
B. cc
C. ccc
D. cccc
E. ccccc
Answer» F.
5.

What will be the output of the following PHP code ?
<?php
$emp = array("Neha", "Sumi", "Abhay", "Krishna");
for ($z = 0; $z < count($emp); $z)
{
if ($emp[$z++] == "Abhay")
continue;
printf ($emp[$z]);
}
?>

A. Neha
B. Sumi
C. SumiAbhay
D. Krishna
E. None of these
Answer» D. Krishna
6.

What will be the output of the following PHP code ?
<?php
for ($z = 0; $z < 20; $z++)
{
print "Mania";
break;
print "Interview";
}
?>

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

What will be the output of the following PHP code ?
<?php
$stu = array("Ajit", "Ats", "Aju", "Rahul");
for ($g=0; $g < count($stu) - 1; $g++)
{
if ($stu[$g++] == "Ats")
continue;
printf ($stu[$g]);
}
?>

A. AjitAtsAjuRahul
B. AjitAtsAju
C. AtsRahul
D. AjitAts
E. None of these
Answer» D. AjitAts
8.

What will be the output of the following PHP code ?
<?php
$emp = array("Ajit", "Ats", "Aju","Rahul");
for ($p = 0; $p < count($emp); $p++)
{
if ($emp[$p] == "Rahul")
continue;
printf ($emp[$p]);
}
?>

A. AjitAtsAjuRahul
B. AjuAtsRahul
C. Error
D. Nothing
E. AjitAtsAju
Answer» F.
9.

What will be the output of the following PHP code ?
<?php
for($g = 0; $g < 15; $g++)
{
for($h = $g; $h > $g; $g--)
print $g;
}
?>

A. Nothing
B. Error
C. 012345......infinite time
D. 543210......infinite time
E. None of these
Answer» B. Error
10.

What will be the output of the following PHP code ?
<?php
for ($v = 0; $v < 5; $v++)
{
for ($u = $v; $u > 0; $v--)
print $v;
}
?>

A. Error
B. 0-1-2-3-4
C. 0-1-2-2-3-3-4-3-4
D. Infinite loop
E. None of these
Answer» E. None of these
11.

What will be the output of the following PHP code ?
<?php
for ($d = 0; -7 ; $d++)
{
print"d";
if ($d == 4)
break;
}
?>

A. d
B. dd
C. ddd
D. dddd
E. ddddd
Answer» F.
12.

What will be the output of the following PHP code ?
<?php
for(;;)
{
print "25";
}
?>

A. Nothing
B. 25
C. Error
D. Infinite loop
E. None of these
Answer» E. None of these
13.

What will be the output of the following PHP code ?
<?php
for ($b = 0; $b = -5; $b = 1)
{
print $b;
if ($b != 2)
break;
}
?>

A. 1
B. 2
C. -5
D. Error
E. None of these
Answer» D. Error
14.

What will be the output of the following PHP code ?
<?php
$p = 0;
for(++$p; ++$p; ++$p)
{
print $p;
if ($p == 6)
break;
}
?>

A. Error
B. 2
C. 24
D. 246
E. None of these
Answer» E. None of these
15.

What will be the output of the following PHP code ?
<?php
for ($p = 1; $p < 10; ++$p)
{
print "*";
}
?>

A. *********
B. ******
C. ***
D. Error
E. Nothing
Answer» B. ******
16.

What will be the output of the following PHP code ?
<?php
for ($k = 5; $k <= 9; print ++$k)
{
print ++$k;
}
?>

A. Error
B. Infinite loop
C. 678910
D. 67891011
E. None of these
Answer» E. None of these
17.

What will be the output of the following PHP code ?
<?php
$n = 10;
for ($n)
{
print $n;
}
?>

A. Nothing
B. 10
C. $n
D. Error
E. None of these
Answer» E. None of these
18.

What will be the output of the following PHP code ?
<?php
for ($g = 0; 0; $g++)
{
print"g";
}
?>

A. 0
B. Error
C. Nothing
D. g
E. None of these
Answer» D. g
19.

What will be the output of the following PHP code ?
<?php
for ($t = 2; $t < 7; $t++)
{
print "Interview n";
continue;
print "Mania";
}
?>

A. Interview
B. Interview 5 time
C. Mania
D. Mania 5 time
E. None of these
Answer» C. Mania
20.

What will be the output of the following PHP code ?
<?php
for ($n = 10; $n < 45; $n++);
print $n;
?>

A. Error
B. 10
C. 45
D. Nothing
E. None of these
Answer» D. Nothing
21.

What will be the output of the following PHP code ?
<?php
for ($number = 1; $number != 20; $number++)
{
print $number;
$number++;
}
?>

A. Nothing
B. Infinite loop
C. Error
D. 1357..........35
E. None of these
Answer» C. Error
22.

What will be the output of the following PHP code ?
<?php
$s = 2;
for (1; $s == 1; $s = 2)
{
print "In for loop statement executed...";
}
print "After for loop statement executed... n";
?>

A. After for loop statement executed...
B. Error
C. In for loop statement executed...
D. Nothing
E. None of these
Answer» B. Error
23.

What will be the output of the following PHP code ?
<?php
$s = 2;
for (1; $s == 1; $s = 2)
{
print "In for loop executed...";
}
print "After for loop statement executed... n";
?>

A. Nothing
B. In for loop executed...
C. After for loop statement executed...
D. Error
E. None of these
Answer» D. Error
24.

What will be the output of the following PHP code ?
<?php
$k = 1;
for ($k++; $k == 1; $k = 2)
print "In for loop execute...";
print "After loop executed... n";

?>

A. Error
B. In for loop execute...
C. After loop executed...
D. Nothing
E. None of these
Answer» D. Nothing
25.

What will be the output of the following PHP code ?
<?php
$num;
for ($num = -4; $num < -6; ++$num)
{
print ++$num;
}
?>

A. Nothing
B. -4
C. -6
D. Error
E. None of these
Answer» B. -4
26.

What will be the output of the following PHP code ?
<?php
for ($n = -5; $n < 10; --$n)
{
print $n;
}
?>

A. Error
B. Nothing
C. -5-6-7-8-9........infinite time
D. -1-2-3-4-5-6-7
E. None of these
Answer» D. -1-2-3-4-5-6-7