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
What does PHP stand for? a) Personal Home Page b) Private Home Page c) PHP: Hypertext Preprocessor d) Preprocessor Home Page
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
PHP files have a default file extension of: a) .html b) .php c) .py d) .js
Which one of the following is not a characteristic of PHP? a) Case sensitive b) Open-source c) Compiled language d) Supports OOP
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
How do you end a PHP statement? a) . b) ; c) : d) !
PHP scripts are enclosed within which tags? a) <script> b) <php> c) <?php ... ?> d) <?script ... ?>
Which of the following is a valid PHP variable? a) $php_var b) &php_var c) @php_var d) %php_var
Which of the following characters is used to indicate a variable in PHP? a) * b) & c) $ d) #
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
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
What will the following code output? <?php echo "Hello, World!"; ?> a) Hello, World! b) “Hello, World!” c) Syntax Error d) No Output
Can PHP be embedded inside JavaScript? a) Yes b) No c) Only in HTML d) Only with CSS
Which HTML attribute is used to run PHP on a server? a) method b) action c) enctype d) none of the above
In which type of file is PHP code written? a) .doc b) .xml c) .php d) .json
How do you write a single-line comment in PHP? a) # comment b) // comment c) /* comment */ d) <!- comment ->
Which of the following is used for multi-line comments in PHP? a) // b) # c) /* */ d) <>
What is the correct way to write a documentation comment in PHP? a) // b) # c) /** */ d) <comment>
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
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
Which of the following functions outputs one or more strings? a) echo() b) print() c) printf() d) all of the above
Can PHP variables contain spaces? a) Yes b) No c) Only in quotes d) Only if initialized
What is the correct way to declare a constant in PHP? a) define() b) constant() c) const() d) $constant
Which function is used to check if a variable is set in PHP? a) isset() b) isdefined() c) checkvar() d) defined()
What will be the output of the following code? $var = 10; echo $var++; a) 10 b) 11 c) 9 d) Error
What does === signify in PHP? a) Greater than b) Equals to c) Identical (equal and same type) d) Assignment
Which one of these functions will return the length of a string? a) length() b) strlen() c) count() d) strlength()
How can you include the content of another PHP file? a) include() b) insert() c) link() d) import()
How can you display information about PHP itself? a) php_info() b) info_php() c) phpinfo() d) about_php()
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”);