PHP MCQs with answers Page - 8

Here, you will find a collection of MCQ questions on PHP. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833K Points
Coach

Q. Which of the looping statements is/are supported by PHP?

  • (A) for each loop
  • (B) do-while loop
  • (C) while loop
  • (D) All of the above

A

Admin • 833K Points
Coach

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

Code:
<?php
$State = "Chennai";
switch ($State) {
case "Mumbai":
echo "I love Mumbai. ";
case "Chennai":
echo "I love Chennai. ";
case "Rajshathan":
echo "I love Rajshatan. "; }
?>
  • (A) I love Chennai. I love Mumbai.
  • (B) I love Mumbai.
  • (C) Error
  • (D) I love Chennai. I love Rajshatan.

A

Admin • 833K Points
Coach

Q. Which of the conditional statements is/are supported by PHP?

  • (A) switch statements
  • (B) if-elseif statements
  • (C) if statements
  • (D) All of the above

A

Admin • 833K Points
Coach

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

Code:
<?php
$num = 6;
$num1 = 6;
echo ($num === $num1);
?>
  • (A) Error
  • (B) 1
  • (C) False
  • (D) 6 === 6

A

Admin • 833K Points
Coach

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

Code:
<?php
$str = "MCQ";
$str .= "Buddy";
echo "$str";
?>
  • (A) MCQ
  • (B) Error
  • (C) Buddy
  • (D) MCQBuddy

A

Admin • 833K Points
Coach

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

Code:
<?php
function track() 
  {
    static $var = 0;
    $var++;
    echo $var;
  }
    track();
    track();
    track();
?>
  • (A) 000
  • (B) 010
  • (C) 110
  • (D) 123

A

Admin • 833K Points
Coach

Q. Which statement will output $x on the screen?

  • (A) echo “$x;”;
  • (B) echo “/$x”;
  • (C) echo “$$x”;
  • (D) echo “$x”;

A

Admin • 833K Points
Coach

Q. Which of the below statements is equivalent to $sum+= $sum ?

  • (A) $sum= $sum+$sum
  • (B) $sum= $sum
  • (C) $sum= $sum+ $sum+ 1
  • (D) $sum= $sum+ 1

A

Admin • 833K Points
Coach

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

Code:
<?php
$math = "25 students";
$Science = 35;
$math = $math + $Science;
echo "$math";
?>
  • (A) 25
  • (B) 35
  • (C) Error
  • (D) 60

A

Admin • 833K Points
Coach

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

Code:
<?php
$num = 10120;
$num1 = (array) $num;
echo $num1[0];
?>
  • (A) 10120
  • (B) Error
  • (C) 101
  • (D) 120