PHP Questions & MCQ With Answers – Basics – 1

This topic of PHP multiple choice questions and answers shelter on PHP basics. It will be feasible for anyone instruction PHP Basics and groundwork.

1. What will be the output of the following php code?

<?php
 $num = 1;
 $num1 = 2;
 print $num . "+". $num1;
 ?>

a) 3
b) 1+2
c) 1.+.2
d) Error

Explanation: .(dot) is used to combine two parts of the statement. Example ( $num . “Hello World” ) will output 1Hello World.

2. Which version of PHP introduced Try/catch Exception?
a)PHP 4
b)PHP 6
c)PHP 5.3
d)PHP 5

Explanation: Version 5 added support for Exception Handling.

3. PHP files have a default file extension of..
a) .html
b) .php
c) .xm]
d) .ph

Explanation: None.

4.What will be the output of the following php code?

<?php
$num = "1";
$num1 = "2";
print $num+$num1;
?>

a) 3
b) 1+2
C) Error
d) 12

Explanation:The numbers inside the double quotes are considered as integers and not string, therefore the value 3 is printed and not 1+2.

5. What does PHP stand for?
i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page
a) Both i) and iii)
b) Both ii) and iv)
c) Only ii)
d) Both i) and ii)

Explanation: PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.

6. A PHP script should start with ___ and end with ___:
a) < ?? >
b) < ? php ?>
c) < php >
d) <?php ?>

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.

7. Which of the following is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT
a) Only iv)
b) All of the mentioned.
c) i), ii) and iii)
d) Only iii)

Explanation: Any of the above editors can be used to type php code and run it.

8. Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS
a) All of the mentioned.
b) Only ii)
c) ii) and iii)
d) ii), iii) and iv)

Explanation: To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform.

9. Which of the following php statement/statements will store 111 in variable num?
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;
a) Both i) and ii)
b) All of the mentioned.
c) Only iii)
d) Only i)

Explanation: You need not specify the datatype in php.

10. We can use ___ to comment a single line?
i) /?
ii) //
iii) #
iv) /* */
a) Only ii)
b) i), iii) and iv)
c) ii), iii) and iv)
d) Both ii) and iv)

Explanation: /* */ can also be use to comment just a single line although it is used for paragraphs. // and # are used only for single line comment.

Comments

comments