PHP Questions and Answers Part-1

PHP solved MCQ Questions :

PHP is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP allows web developers to create dynamic content and to interact with databases. This section focus on all topics of the PHP subject. Here you can get important mcq questions on PHP with answers. These questions will help you to prepare for interviews, entrance exams, online tests, and semester exams. These PHP multiple choice questions are for both freshers and experienced candidates.

PHP MCQ Chapter Wise :

Here you will find a list of important questions and answers with detailed solution on PHP in MCQ quiz style for competitive exams and interviews. Here, You can practice these MCQs chapter-wise for FREE.

Below section consists of important multiple choice questions on PHP with answers -:

1. Which of the below statements is equivalent to $add += $add?
a) $add = $add + $add + 1
b) $add = $add +$add
c) $add = $add + 1
d) $add = $add

Answer: b
Explanation: a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction, multiplication, division etc.

2. PHP files have a default file extension of_______.
a) .html
b) .xml
c) .php
d) .hphp

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

3. A script is a_______.
a) Program or sequence of instructions that is interpreted or carried out by processor directly
b) Program or sequence of instruction that is interpreted or carried out by another program
c) Program or sequence of instruction that is interpreted or carried out by web server only
d) None of the above

Answer: b
Explanation: A script is a program or sequence of instruction that is interpreted or carried out by another program.

4. Which one of the following PHP functions can be used to find files?
a) fold()
b) file()
c) glob()
d) get_file()

Answer: c
Explanation: The function glob() returns an array of filenames or directories which matches a specified pattern. The function returns an array of files/directories, or it will return FALSE on failure.

5. When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
a) chr( );
b) asc( );
c) ord( );
d) val( );

Answer: c
Explanation: When we need to obtain the ASCII value of a character we apply ord( ); in PHP.

6. A variable name can only contain ____________?
a) alphanumeric characters
b) underscores
c) Both A and B
d) None of the above

Answer: c
Explanation: A variable name can only contain alphanumeric characters and underscores in their name.

7. Which one of the following PHP function is used to determine a file’s last access time?
a) fileatime()
b) filectime()
c) fileltime()
d) filetime()

Answer: a
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.

8. Which one of the following function is capable of reading a specific number of characters form a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()

Answer: a
Explanation: Its prototype is string fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is assumed.

9. PHP variables are case-sensitive?
a) True
b) False
c) For "sum" variable it is case-sensitive
d) None of the above

Answer: a
Explanation: PHP variables are case-sensitive, i.e., $lfc and $LFC are treated differently.

10. What will be the output of the following PHP code?
<?php
$a = 1;
$b = 2;
$c = 3;
echo ($a * (($b) - $c));
?>
a) 1
b) -1
c) 2
d) -2

Answer: b
Explanation: The innermost bracket is evaluated first since it covers only variable B, it is as good as not using brackets, then $b- $c action will be performed.