MCQs on Introduction to PHP | PHP Basics

PHP, a widely-used open-source scripting language, powers dynamic web development by embedding code within HTML. Known for its simplicity and flexibility, PHP plays a pivotal role in server-side scripting, making it essential for creating interactive websites.


Multiple Choice Questions (MCQs)

1. Introduction to PHP

  1. What does PHP stand for?
    a) Personal Home Page
    b) Private Home Page
    c) PHP: Hypertext Preprocessor
    d) Preprocessor Home Page
  2. Which of the following is true about PHP?
    a) It’s a client-side scripting language
    b) It is used to create static websites
    c) It is a server-side scripting language
    d) It cannot be embedded in HTML
  3. PHP files have a default file extension of:
    a) .html
    b) .php
    c) .py
    d) .js
  4. Which one of the following is not a characteristic of PHP?
    a) Case sensitive
    b) Open-source
    c) Compiled language
    d) Supports OOP
  5. Which of the following is a popular server that can run PHP?
    a) Internet Information Services (IIS)
    b) Apache
    c) Tomcat
    d) WebLogic

2. PHP Syntax and Structure

  1. How do you end a PHP statement?
    a) .
    b) ;
    c) :
    d) !
  2. PHP scripts are enclosed within which tags?
    a) <script>
    b) <php>
    c) <?php ... ?>
    d) <?script ... ?>
  3. Which of the following is a valid PHP variable?
    a) $php_var
    b) &php_var
    c) @php_var
    d) %php_var
  4. Which of the following characters is used to indicate a variable in PHP?
    a) *
    b) &
    c) $
    d) #
  5. PHP is case-sensitive when it comes to:
    a) Keywords
    b) Functions
    c) Variables
    d) All of the above

3. PHP Tags and Embedding in HTML

  1. How can you embed PHP code within an HTML document?
    a) Using <html> tags
    b) Using <?php ... ?> tags
    c) Using <script> tags
    d) Using <php> tags
  2. What will the following code output? <?php echo "Hello, World!"; ?> a) Hello, World!
    b) “Hello, World!”
    c) Syntax Error
    d) No Output
  3. Can PHP be embedded inside JavaScript?
    a) Yes
    b) No
    c) Only in HTML
    d) Only with CSS
  4. Which HTML attribute is used to run PHP on a server?
    a) method
    b) action
    c) enctype
    d) none of the above
  5. In which type of file is PHP code written?
    a) .doc
    b) .xml
    c) .php
    d) .json

4. PHP Comments (Single-line, Multi-line, Doc-comments)

  1. How do you write a single-line comment in PHP?
    a) # comment
    b) // comment
    c) /* comment */
    d) <!- comment ->
  2. Which of the following is used for multi-line comments in PHP?
    a) //
    b) #
    c) /* */
    d) <>
  3. What is the correct way to write a documentation comment in PHP?
    a) //
    b) #
    c) /** */
    d) <comment>
  4. Which type of comment can be used to generate documentation automatically?
    a) Single-line comment
    b) Multi-line comment
    c) Doc-comments
    d) HTML comments
  5. How does PHP treat comments in the script?
    a) As code
    b) As syntax errors
    c) Ignores them during execution
    d) Treats as part of output

5. Miscellaneous Questions on PHP Basics

  1. Which of the following functions outputs one or more strings?
    a) echo()
    b) print()
    c) printf()
    d) all of the above
  2. Can PHP variables contain spaces?
    a) Yes
    b) No
    c) Only in quotes
    d) Only if initialized
  3. What is the correct way to declare a constant in PHP?
    a) define()
    b) constant()
    c) const()
    d) $constant
  4. Which function is used to check if a variable is set in PHP?
    a) isset()
    b) isdefined()
    c) checkvar()
    d) defined()
  5. What will be the output of the following code? $var = 10; echo $var++; a) 10
    b) 11
    c) 9
    d) Error
  6. What does === signify in PHP?
    a) Greater than
    b) Equals to
    c) Identical (equal and same type)
    d) Assignment
  7. Which one of these functions will return the length of a string?
    a) length()
    b) strlen()
    c) count()
    d) strlength()
  8. How can you include the content of another PHP file?
    a) include()
    b) insert()
    c) link()
    d) import()
  9. How can you display information about PHP itself?
    a) php_info()
    b) info_php()
    c) phpinfo()
    d) about_php()
  10. How do you declare an array in PHP?
    a) $array = array(“value1”, “value2”);
    b) array[] = {“value1”, “value2”};
    c) $array = {“value1”, “value2”};
    d) array(“value1”, “value2”);

Answer Key

QnoAnswer
1c) PHP: Hypertext Preprocessor
2c) It is a server-side scripting language
3b) .php
4c) Compiled language
5b) Apache
6b) ;
7c) <?php … ?>
8a) $php_var
9c) $
10c) Variables
11b) Using <?php … ?> tags
12a) Hello, World!
13a) Yes
14d) none of the above
15c) .php
16b) // comment
17c) /* */
18c) /** */
19c) Doc-comments
20c) Ignores them during execution
21d) all of the above
22b) No
23a) define()
24a) isset()
25a) 10
26c) Identical (equal and same type)
27b) strlen()
28a) include()
29c) phpinfo()
30a) $array = array(“value1”, “value2”);

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top