Explore topic-wise MCQs in Php.

This section includes 41 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 ?<?phpstatic $n = 5;function calc(){ echo $n; $n++;}calc();calc();calc();?>

A. 0
B. 5
C. Undefined variable: n
D. 5 and 0
E. None of these
Answer» D. 5 and 0
2.

What will be the output of the following PHP code ?<?php$t = 2;function calculation(){ echo $GLOBALS['t']; $t++;}calculation();calculation();calculation();?>

A. Error
B. 2
C. 22
D. 222
E. None of these
Answer» E. None of these
3.

What will be the output of the following PHP code ?<?php$p=7;function calc(){ echo $GLOBALS['p']; $GLOBALS['p']++;}calc();calc();calc();?>

A. 7
B. 789
C. 78
D. 89
E. None of these
Answer» C. 78
4.

What will be the output of the following PHP code ?<?phpfunction calc(){ static $p = 5; echo $p; $p++;}calc();calc();calc();?>

A. 5
B. 56
C. 567
D. 5678
E. None of these
Answer» D. 5678
5.

What will be the output of the following PHP code ?<?phpfunction calc(){ $n = 5; echo $n; $n++;}calc();calc();calc();?>

A. 5
B. Nothing
C. Error
D. 555
E. None of these
Answer» E. None of these
6.

What will be the output of the following PHP code ?<?php$p = 15;$q = 25;function calc(){ $q = $GLOBALS['p'] + $GLOBALS['q'];} calc();echo $q;?>

A. Error
B. 15
C. 25
D. Nothing
E. None of these
Answer» D. Nothing
7.

What will be the output of the following PHP code ?<?php$n1 = 15;$n2 = 18;function Calc(){ $GLOBALS['n2'] = $GLOBALS['n1'] + $GLOBALS['n2'];} Calc();echo $n2;?>

A. 15
B. 18
C. 33
D. Error
E. None of these
Answer» D. Error
8.

What will be the output of the following PHP code ?<?php$str1 = "$Test";$str2 = " $Example";echo $str1, $str2;?>

A. $Test
B. $Example
C. $Test $Example
D.
E. None of these
Answer» E. None of these
9.

What will be the output of the following PHP code ?<?php$p = "$Test";$q = " $Example";echo $p, $q;?>

A. $Example
B.
C. $Test
D. Nothing
E. None of these
Answer» B.
10.

What will be the output of the following PHP code ?<?php$p = "$Test";$q = "/$Example";echo $p,$q;?>

A. Test
B. Example
C. /
D. Nothing
E. None of these
Answer» D. Nothing
11.

What will be the output of the following PHP code ?<?php$m = 15;$n = 8;$p = fun(15,8);function fun($m,$n){ $n = 7; return $m - $n + $n - $m; }echo $m;echo $n;echo $p;?>

A. Error
B. 18
C. 8
D. 1580
E. None of these
Answer» E. None of these
12.

What will be the output of the following PHP code ?<?php$m = 31, 14, 15, 61;echo "$m";?>

A. Nothing
B. Error
C. 61
D. 31
E. None of these
Answer» C. 61
13.

What will be the output of the following PHP code ?<?phpfunction Res($p,$q){ $p = 7; $q = 8; $r = $p + $q / $q + $p; echo "$r";}Res(8, 7); ?>

A. 7
B. 8
C. 15
D. Error
E. None of these
Answer» D. Error
14.

What will be the output of the following PHP code ?<?php$p = 6;$q = 5;function Res($p , $q ){ $r = $p+$q/$q+$p; echo "$r";} echo $p;echo $q;echo $r; Res(5, 6);?>

A. 6511
B. 611
C. Nothing
D. Error
E. None of these
Answer» B. 611
15.

What will be the output of the following PHP code ?<?php$p = 6;$q = 5;function Res($p = 5, $q = 6){ $r = $p+$q/$q+$p; echo "$r";} echo $p;echo $q;echo $r; Res($p, $q);?>

A. Nothing
B. 6
C. 5
D. 65
E. 6513
Answer» F.
16.

What will be the output of the following PHP code ?<?php$n = 25;function Res(){ $n = 15; echo "$n";}Res();echo "$n";?>

A. 25
B. 15
C. 1525
D. Error
E. None of these
Answer» D. Error
17.

What will be the output of the following PHP code ?<?php$p = 51;function Result(){ echo "$p";}Result();?>

A. Error
B. 51
C. Nothing
D. 51 51
E. None of these
Answer» D. 51 51
18.

What will be the output of the following PHP code ?<?php$n = 25;{ echo "$n";}?>

A. Error
B. 25
C. Nothing
D. $n
E. None of these
Answer» C. Nothing
19.

What will be the output of the following PHP code ?<?php$n = 10;{ $n = 20; echo "$n";}echo "$n";?>

A. 10
B. Error
C. 20
D. 2020
E. None of these
Answer» E. None of these
20.

What will be the output of the following PHP code ?<?php$n;echo "$n";?>

A. 0
B. True
C. 1
D. False
E. Undefined variable: n
Answer» F.
21.

What will be the output of the following PHP code ?<?php$hello = "Hello";$interveiw = "Interveiw";$mania = "Mania";echo "$interveiw";$hello; $mania; ?>

A. Hello
B. Interveiw
C. Mania
D. All of above
E. None of these
Answer» C. Mania
22.

What will be the output of the following PHP code ?<?phpvar $five = 5;var $six = 6;echo $five / $six * $five / $six * $six;?>

A. Nothing
B. Error
C. 5
D. 0.25
E. None of these
Answer» C. 5
23.

What will be the output of the following PHP code ?<?phpint $five = 5;echo "$five";?>

A. $five
B. 5
C. Error
D. Nothing
E. None of these
Answer» D. Nothing
24.

What will be the output of the following PHP code ?<?php$9nine = 9;$8eight = 8;$6six = 6;echo $9nine + $8eight / $6six - 3;?>

A. 9
B. 8
C. 5.6
D. Error
E. None of these
Answer» E. None of these
25.

What will be the output of the following PHP code ?<?php$one1 = 1;$nine9 = 9;$eight8 = 8;echo $nine9 + $eight8 / $one1 - 2;?>

A. 1
B. 15
C. 9
D. 8
E. Error
Answer» C. 9
26.

What will be the output of the following PHP code ?<?phpecho $Yellow;?>

A. Nothing
B. True
C. False
D. 0
E. Error
Answer» F.
27.

What will be the output of the following PHP code ?<?php$Fiv-e = 5;$Si-x = 6;$Seve-n = 7;$Eigh-t = 8;echo "$Fiv-e / $Si-x + $Seve-n / $Eigh-t";?>

A. Nothing
B. 1.25
C. 3.52
D. Error
E. None of these
Answer» E. None of these
28.

What will be the output of the following PHP code ?<?php$Fiv_e = 5;$Si_x = 6;$Seve_n = 7;$Eigh_t = 8;echo "$Fiv_e / $Si_x + $Seve_n / $Eigh_t";?>

A. Error
B. 1.25
C. Nothing
D. 5.25
E. None of these
Answer» C. Nothing
29.

What will be the output of the following PHP code ?<?php$Fiv$e = 5;$Si$x = 6;$Seve$n = 7;$Eigh$t = 8;echo "$Fiv$e / $Si$x + $Seve$n / $Eigh$t";?>

A. 0.25
B. Error
C. 0
D. 25.2
E. None of these
Answer» C. 0
30.

What will be the output of the following PHP code ?<?phpFive = 5;Six = 6;Seven = 7;Eight = 8;echo "Five / Six + Seven / Eight";?>

A. Error
B. 5
C. 5.5
D. 1
Answer» B. 5
31.

What will be the output of the following PHP code ?<?php$n1 = 7.5;$n2 = 4;$n3 = 4;echo $n1 / $n2 / $n3;?>

A. 0.46875
B. 7.5
C. 4
D. 0
E. None of these
Answer» B. 7.5
32.

What will be the output of the following PHP code ?<?php$r = 8;$s = -6;$t = 22;echo 8 + $s * $t / $r;?>

A. 8
B. -6
C. -8.5
D. 11
E. None of these
Answer» D. 11
33.

What will be the output of the following PHP code ?<?php$p = -2;$q = 2;$r = $p * $q + $r;echo $r;?>

A. Undefined variable
B. Undefined variable: r -4
C. 2
D. -2
E. None of these
Answer» C. 2
34.

What will be the output of the following PHP code ?<?php$a = 23;$b = 15;$c = 25;echo $a + $b - $c / ($c - $b);?>

A. 35.5
B. 23
C. 15
D. 25
E. None of these
Answer» B. 23
35.

What will be the output of the following PHP code ?<?php$p = 12;$q = 21;$r = 13;echo $p + $q - $r / ($r - $q);?>

A. 12
B. 34
C. 21
D. 13
E. 34.625
Answer» F.
36.

What will be the output of the following PHP code ?<?php$m = 15;$n = 5;$t = 7;echo ($m % ($n) + $t);?>

A. 15
B. 5
C. 7
D. Error
E. None of these
Answer» D. Error
37.

What will be the output of the following PHP code ?<?php$p = 22;$q = 5;$r = 4;echo $p % $q % $r;?>

A. 22
B. 5
C. 4
D. 2
E. None of these
Answer» E. None of these
38.

What will be the output of the following PHP code ?<?php$p = 11;$q = 3;echo $p % $q;?>

A. Nothing
B. $p % $q
C. 2
D. Error
E. None of these
Answer» D. Error
39.

What will be the output of the following PHP code ?<?php$a = 41;$b = 13;$c = 10;$d = $c + $a + $b;echo "$d";?>

A. Error
B. 41
C. 13
D. 10
E. 64
Answer» F.
40.

What will be the output of the following PHP code ?<?php$n1 = 14;$n2 = 31;$n3 = 11;echo "$n1 = $n1 + $n2 + $n3";?>

A. 14 = 14 + 31 + 11
B. Error
C. $n1 = $n1 + $n2 + $n3
D. Nothing
E. None of these
Answer» B. Error
41.

What will be the output of the following PHP code ?<?php$n1 = 15;$n2 = 11;$R = "$n1 + $n2";echo "$R";?>

A. 15 + 11
B. 15
C. $n1 + $n2
D. 11
E. None of these
Answer» B. 15