PHP Multiple Choice Questions – Basics

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

Answer: d
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

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

3. What should be the correct syntax to write a PHP code?
a) < php >
b) < ? php ?>
c) <? ?>
d) <?php ?>
View Answer

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.

4. Which of the following is/are a PHP code editor?

    i) Notepad
    ii) Notepad++
    iii) Adobe Dreamweaver
    iv) PDT
Note: Join free Sanfoundry classes at Telegram or Youtube

a) Only iv)
b) i), ii), iii) and iv)
c) i), ii) and iii)
d) Only iii)
View Answer

Answer: b
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
advertisement

a) i), ii), iii) and iv)
b) Only ii)
c) ii) and iii)
d) ii), iii) and iv)
View Answer

Answer: d
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

Answer: d
Explanation: PHP 5 version and later versions added support for Exception Handling.
advertisement

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

Answer: c
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

Answer: c
Explanation: You need not specify the datatype in php.

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

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

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

Answer: b
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?

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

a) 3
b) 1+2
c) Error
d) 12
View Answer

Answer: a
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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.