PHP MCQs with answers Page - 21

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

Q. What is the name of an array that stores all global variables in PHP?

  • (A) $GLOBAL[]
  • (B) $global[]
  • (C) $GLOBALS[]
  • (D) $PHP_GLOBALS[]

A

Admin • 832.01K Points
Coach

Q. In the syntax of $GLOBALS[index], what does "index" hold?

  • (A) Index (starting from 0) of the variable
  • (B) Index (starting from 1) of the variable
  • (C) Name of the variable
  • (D) Line number of the variable where the variable was declared

A

Admin • 832.01K Points
Coach

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

Code:
<?php
function Increment(){
    static $num = 0;
    echo "$num";
    $num++;
}

Increment();
Increment();
Increment();
?>
  • (A) 000
  • (B) 111
  • (C) 011
  • (D) 012

A

Admin • 832.01K Points
Coach

Q. Which statement is faster echo or print?

  • (A) echo
  • (B) print
  • (C) either A or B
  • (D) None of these

A

Admin • 832.01K Points
Coach

Q. What is the correct syntax of echo statement in PHP?

  • (A) echo
  • (B) echo()
  • (C) echo = ()
  • (D) Both A and B.

A

Admin • 832.01K Points
Coach

Q. There is a variable "name" that contains the name of a person, which is/are the correct echo statement(s) to print the "name" suffix with "Hello".

  • (A) echo "Hello $name";
  • (B) echo "Hello " . $name;
  • (C) echo ("Hello $name");
  • (D) All of the above

A

Admin • 832.01K Points
Coach

Q. What is the correct syntax of print statement in PHP?

  • (A) print
  • (B) print()
  • (C) print = ()
  • (D) Both A and B.

A

Admin • 832.01K Points
Coach

Q. There is a variable "name" that contains the name of a person, which is/are the correct print statement(s) to print the "name" suffix with "Hello".

  • (A) print "Hello $name";
  • (B) print "Hello " . $name;
  • (C) print ("Hello $name");
  • (D) All of the above

A

Admin • 832.01K Points
Coach

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

Code:
<?php
$a = 5;
$b = 10;

print ("$a, $b+10");
?>
  • (A) 5, 10+10
  • (B) 5, 20
  • (C) 5 10+10
  • (D) 5 20

A

Admin • 832.01K Points
Coach

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

Code:
<?php
var_dump (print "Hello");
?>
  • (A) Helloint(5)
  • (B) Helloint(6)
  • (C) Helloint(1)
  • (D) Hellonumber(5)

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ