PHP Objective Questions and Answers

PHP Objective Questions and Answers Here provide PHP Objective Questions with Answers. you can learn and practice questions on PHP Programming.

1) What is PHP?

A) PHP is an open-source programming language
B) PHP is used to develop dynamic and interactive websites
C) PHP is a server-side scripting language
D) All of the mentioned

Answer: D
Explanation: PHP is an open-source server-side scripting language that is used to build dynamic and interactive web pages or web applications.

2) Who is the father of PHP?

A) Drek Kolkevi
B) Rasmus Lerdorf
C) Willam Makepiece
D) List Barely

Answer: B
Explanation: PHP was originally created by Rasmus Lerdorf in 1994.

3) What does PHP stand for?

A) PHP stands for Preprocessor Home Page
B) PHP stands for Pretext Hypertext Processor
C) PHP stands for Hypertext Preprocessor
D) PHP stands for Personal Hyper Processor

Answer: C
Explanation: PHP previously stood for Personal Home Page now stands for “Hypertext Preprocessor”.

4) Which of the following is the correct syntax to write a PHP code?

A) <?php ?>
B) < php >
C) < ? php ?>
D) <? ?>

Answer: D
Explanation: Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them.

5) Which of the following is the correct way to add a comment in PHP code?

A) #
B) //
C) /* */
D) All of the mentioned

Answer: D
Explanation: In PHP, /* */ can also be used to comment just a single line although it is used for paragraphs. // and # are used only for single-line comments.

6) Which of the following is the default file extension of PHP files?

A) .php
B) .ph
C) .xml
D) .html

Answer: A
Explanation: To run a PHP file on the server, it should be saved as AnyName.php

7) How to define a function in PHP?

A) functionName(parameters) {function body}
B) function {function body}
C) function functionName(parameters) {function body}
D) data type functionName(parameters) {function body}

Answer: C
Explanation: PHP allows us to create our own user-defined functions. Any name ending with an open and closed parenthesis is a function. The keyword function is always used to begin a function.

8) What will be the output of the following PHP code?

$x = 10;
$y = 20;
if ($x > $y && 1||1)
    print "100 PHP MCQ" ;
    print "Welcome to Study2Online";

A) no output
B) Welcome to Study2Online
C) 100 PHP MCQ
D) error

Answer: C
Explanation: Expression evaluates to true.


9) Which is the right way of declaring a variable in PHP?

A) $3hello
B) $_hello
C) $this
D) $5_Hello

Answer: B
Explanation: A variable in PHP can not start with a number, also $this is mainly used to refer properties of a class so we can’t use $this as a user defined variable name.

10. What will be the output of the following PHP program?

$fruits = array ("apple", "orange", array ("pear", "mango"),"banana");
echo (count($fruits, 1));

A) 6
B) 5
C) 4
D) 3

Answer: A
Explanation: function count() will return the number of elements in an array. The parameter 1 counts the array recursively i.e it will count all the elements of multidimensional arrays.

Be the first to comment

Leave a Reply

Your email address will not be published.