PHP MCQs with answers Page - 2

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 • 828.03K Points
Coach

Q. Which of the following PHP statements will output Hello World on the screen?
1. echo (“Hello World”);
2. print (“Hello World”);
3. printf (“Hello World”);
4. sprintf (“Hello World”);

  • (A) 1 and 2
  • (B) 1, 2 and 3
  • (C) All of the mentioned
  • (D) 1, 2 and 4

A

Admin • 828.03K Points
Coach

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

Code:
<?php
$color = "maroon";
$var = $color[2];
echo "$var";
?>
  • (A) a
  • (B) $var
  • (C) r
  • (D) Error

A

Admin • 828.03K Points
Coach

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

Code:
<?php
$score = 1234;
$scoreboard = (array) $score;
echo $scoreboard[0];
?>
  • (A) 1
  • (B) Error
  • (C) 1234
  • (D) 2

A

Admin • 828.03K Points
Coach

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

Code:
<?php
$total = "25 students";
$more = 10;
$total = $total + $more;
echo "$total";
?>
  • (A) Error
  • (B) 35 students
  • (C) 35
  • (D) 25 students

A

Admin • 828.03K Points
Coach

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

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

A

Admin • 828.03K 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 • 828.03K Points
Coach

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

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

A

Admin • 828.03K Points
Coach

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

Code:
<?php
$a = "clue";
$a .= "get";
echo "$a";
?>
  • (A) get
  • (B) true
  • (C) false
  • (D) clueget

A

Admin • 828.03K Points
Coach

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

Code:
<?php
$a = 5;
$b = 5;
span class="sys-fun">echo ($a === $b);
?>
  • (A) 5 === 5
  • (B) Error
  • (C) 1
  • (D) False

A

Admin • 828.03K Points
Coach

Q. Which of the below symbols is a newline character?

  • (A)
  • (B)
  • (C) /n
  • (D) /r