This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Basics”.
1. 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)
View Answer
Explanation: PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.
2. PHP files have a default file extension of_______
a) .html
b) .xml
c) .php
d) .ph
View Answer
Explanation: To run a php file on the server, it should be saved as AnyName.php
3. What should be the correct syntax to write a PHP code?
a) < php >
b) < ? php ?>
c) <? ?>
d) <?php ?>
View Answer
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.
4. Which of the following is/are a PHP code editor?
i) Notepad ii) Notepad++ iii) Adobe Dreamweaver iv) PDT
a) Only iv)
b) i), ii), iii) and iv)
c) i), ii) and iii)
d) Only iii)
View Answer
Explanation: Any of the above editors can be used to type php code and run it.
5. Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver ii) XAMPP iii) Apache and PHP iv) IIS
a) i), ii), iii) and iv)
b) Only ii)
c) ii) and iii)
d) ii), iii) and iv)
View Answer
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.
6. Which version of PHP introduced Try/catch Exception?
a) PHP 4
b) PHP 5
c) PHP 6
d) PHP 5 and later
View Answer
Explanation: PHP 5 version and later versions added support for Exception Handling.
7. How should we add a single line comment in our PHP code?
i) /? ii) // iii) # iv) /* */
a) Only ii)
b) i), iii) and iv)
c) ii), iii) and iv)
d) Both ii) and iv)
View Answer
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.
8. 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) i), ii), iii) and iv)
c) Only iii)
d) Only i)
View Answer
Explanation: You need not specify the datatype in php.
9. 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
View Answer
Explanation: .(dot) is used to combine two parts of the statement. Example ($num . “Hello World”) will output 1Hello World.
10. 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
View Answer
Explanation: The numbers inside the double quotes are considered as integers and not string, therefore the value 3 is printed and not 1+2.
More MCQs on PHP Basics:
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Check PHP Books
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Programming Internship
- Practice MCA MCQs