PHP Quiz

PHP is a server-side scripting language that powers a large share of the web, including WordPress. This quiz checks syntax, variables, arrays, functions, forms, sessions and how PHP works with databases.

What this quiz covers

Study tip: Build a simple contact form that stores messages in a database; it touches most of the topics in this quiz.

Questions, answers and explanations

1. What does PHP stand for?

  1. Personal Home Page
  2. PHP: Hypertext Preprocessor
  3. Private Home Page
  4. Programming Home Page

Answer: PHP: Hypertext Preprocessor

PHP officially stands for PHP: Hypertext Preprocessor.

2. PHP is mainly used for?

  1. Web Development
  2. Game Development
  3. Operating Systems
  4. Machine Learning

Answer: Web Development

PHP is a server-side scripting language used for web development.

3. Which symbol is used to start a variable in PHP?

  1. $
  2. #
  3. @
  4. &

Answer: $

Every PHP variable starts with the $ symbol.

4. Which company created PHP?

  1. Microsoft
  2. Google
  3. Rasmus Lerdorf
  4. Oracle

Answer: Rasmus Lerdorf

PHP was created by Rasmus Lerdorf in 1994.

5. PHP code is executed on the?

  1. Browser
  2. Server
  3. Client
  4. Database

Answer: Server

PHP is a server-side scripting language.

6. Which tags are used to write PHP code?

  1. <?php ?>
  2. <php></php>
  3. <script></script>
  4. <? ?>

Answer: <?php ?>

PHP code is written inside <?php ?> tags.

7. Which function displays output in PHP?

  1. echo
  2. print
  3. Both echo and print
  4. display

Answer: Both echo and print

Both echo and print can be used to display output.

8. Which operator is used for string concatenation in PHP?

  1. .
  2. +
  3. &
  4. *

Answer: .

The dot (.) operator concatenates strings in PHP.

9. Which superglobal stores form data sent using POST?

  1. $_POST
  2. $_GET
  3. $_FORM
  4. $_REQUEST

Answer: $_POST

$_POST contains data sent through HTTP POST.

10. Which function is used to determine the length of a string?

  1. strlen()
  2. count()
  3. length()
  4. size()

Answer: strlen()

strlen() returns the length of a string.

11. Which function is used to count the number of elements in an array?

  1. count()
  2. sizeof()
  3. Both count() and sizeof()
  4. length()

Answer: Both count() and sizeof()

Both count() and sizeof() return the number of elements in an array.

12. Which statement is used for decision making in PHP?

  1. if
  2. switch
  3. Both if and switch
  4. loop

Answer: Both if and switch

PHP provides both if and switch statements for decision making.

13. Which loop executes at least one time?

  1. while
  2. for
  3. do...while
  4. foreach

Answer: do...while

The do...while loop executes its body at least once.

14. Which keyword is used to define a function in PHP?

  1. function
  2. define
  3. method
  4. func

Answer: function

Functions in PHP are declared using the function keyword.

15. Which superglobal contains URL parameters?

  1. $_GET
  2. $_POST
  3. $_SESSION
  4. $_COOKIE

Answer: $_GET

$_GET stores data sent through the URL query string.

16. Which superglobal is used to store session variables?

  1. $_SESSION
  2. $_COOKIE
  3. $_SERVER
  4. $_FILES

Answer: $_SESSION

$_SESSION stores session data across multiple pages.

17. Which function is used to connect to a MySQL database using MySQLi?

  1. mysqli_connect()
  2. mysql_connect()
  3. connect_db()
  4. db_connect()

Answer: mysqli_connect()

mysqli_connect() establishes a connection to a MySQL database.

18. Which keyword is used to include another PHP file?

  1. include
  2. require
  3. Both include and require
  4. import

Answer: Both include and require

Both include and require are used to insert one PHP file into another.

19. Which function is used to terminate script execution?

  1. exit()
  2. die()
  3. Both exit() and die()
  4. stop()

Answer: Both exit() and die()

Both exit() and die() immediately terminate PHP script execution.

20. Which of the following is a major advantage of PHP?

  1. Open Source
  2. Cross Platform
  3. Easy Database Integration
  4. All of the above

Answer: All of the above

PHP is open source, works across platforms, and integrates easily with databases like MySQL.

Take the timed quiz