PHP Questions and Answers Part-6

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)

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

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

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

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
a) i), ii), iii) and iv)
b) Only ii)
c) ii) and iii)
d) ii), iii) and iv)

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

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

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)

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

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?
<?php
$num = "1";
$num1 = "2";
print $num+$num1;
?>
a) 3
b) 1+2
c) Error
d) 12

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.