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
- Syntax, variables and operators
- Arrays and functions
- Forms, GET and POST
- Sessions, cookies and databases
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?
- Personal Home Page
- PHP: Hypertext Preprocessor
- Private Home Page
- Programming Home Page
Answer: PHP: Hypertext Preprocessor
PHP officially stands for PHP: Hypertext Preprocessor.
2. PHP is mainly used for?
- Web Development
- Game Development
- Operating Systems
- 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?
- $
- #
- @
- &
Answer: $
Every PHP variable starts with the $ symbol.
4. Which company created PHP?
- Microsoft
- Rasmus Lerdorf
- Oracle
Answer: Rasmus Lerdorf
PHP was created by Rasmus Lerdorf in 1994.
5. PHP code is executed on the?
- Browser
- Server
- Client
- Database
Answer: Server
PHP is a server-side scripting language.
6. Which tags are used to write PHP code?
- <?php ?>
- <php></php>
- <script></script>
- <? ?>
Answer: <?php ?>
PHP code is written inside <?php ?> tags.
7. Which function displays output in PHP?
- echo
- Both echo and print
- 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?
- .
- +
- &
- *
Answer: .
The dot (.) operator concatenates strings in PHP.
9. Which superglobal stores form data sent using POST?
- $_POST
- $_GET
- $_FORM
- $_REQUEST
Answer: $_POST
$_POST contains data sent through HTTP POST.
10. Which function is used to determine the length of a string?
- strlen()
- count()
- length()
- size()
Answer: strlen()
strlen() returns the length of a string.
11. Which function is used to count the number of elements in an array?
- count()
- sizeof()
- Both count() and sizeof()
- 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?
- if
- switch
- Both if and switch
- loop
Answer: Both if and switch
PHP provides both if and switch statements for decision making.
13. Which loop executes at least one time?
- while
- for
- do...while
- 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?
- function
- define
- method
- func
Answer: function
Functions in PHP are declared using the function keyword.
15. Which superglobal contains URL parameters?
- $_GET
- $_POST
- $_SESSION
- $_COOKIE
Answer: $_GET
$_GET stores data sent through the URL query string.
16. Which superglobal is used to store session variables?
- $_SESSION
- $_COOKIE
- $_SERVER
- $_FILES
Answer: $_SESSION
$_SESSION stores session data across multiple pages.
17. Which function is used to connect to a MySQL database using MySQLi?
- mysqli_connect()
- mysql_connect()
- connect_db()
- db_connect()
Answer: mysqli_connect()
mysqli_connect() establishes a connection to a MySQL database.
18. Which keyword is used to include another PHP file?
- include
- require
- Both include and require
- 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?
- exit()
- die()
- Both exit() and die()
- 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?
- Open Source
- Cross Platform
- Easy Database Integration
- All of the above
Answer: All of the above
PHP is open source, works across platforms, and integrates easily with databases like MySQL.