PHP Mastery Quiz: Test Your Server-Side Scripting Skills! Quiz

  1. Understanding PHP Basics

    Which of the following is true about PHP as described in the context of web development?

    1. A. PHP is a client-side scripting language embedded in CSS.
    2. B. PHP is a server-side scripting language that can be embedded with HTML.
    3. C. PHP compiles directly to machine code before being run.
    4. D. PHP is strictly used for mobile app development.
    5. E. PHP only runs on Windows operating systems.
  2. PHP Redirection

    What is the correct PHP function to redirect users to a different page, for example, after submitting a form?

    1. A. redirect_to('newpage.php');
    2. B. move('newpage.php');
    3. C. header('Location: newpage.php');
    4. D. navigate('newpage.php');
    5. E. location('newpage.php');
  3. Session Functions Distinction

    Which of the following best explains the main difference between session_unset() and session_destroy() in PHP?

    1. A. session_unset() deletes the session file; session_destroy() clears only the variables.
    2. B. session_unset() clears session variables, leaving the session active; session_destroy() removes all data and invalidates the session.
    3. C. session_destroy() only deletes cookies; session_unset() removes the entire session.
    4. D. Both session_unset() and session_destroy() do exactly the same thing.
    5. E. Session functions can only be used in PHP 5.6 and below.
  4. PHP Variable Naming

    Which of the following is an invalid PHP variable name?

    1. A. $variable_1
    2. B. $_userName
    3. C. $3variable
    4. D. $user_name3
    5. E. $Variable
  5. PHP Array Handling

    Suppose you want to count the number of elements in a PHP array called $colors. Which function should you use?

    1. A. length($colors)
    2. B. sizeof($colors)
    3. C. count($colors)
    4. D. elements($colors)
    5. E. num($colors)
  6. Error Reporting in PHP

    What is the effect of setting error_reporting(0) in a PHP script?

    1. A. Only critical errors are displayed.
    2. B. Syntax errors get highlighted.
    3. C. No error messages are shown during the execution of the script.
    4. D. All errors and warnings are shown vividly.
    5. E. The script execution stops immediately on error.
  7. PHP Data Types

    If $x is defined as $x = array('apple', 'banana', 'cherry'); what is the data type of $x?

    1. A. String
    2. B. Integer
    3. C. Array
    4. D. Object
    5. E. Boolean
  8. String Concatenation

    How do you concatenate two strings 'Hello' and 'World' in PHP?

    1. A. 'Hello' + 'World';
    2. B. concat('Hello', 'World');
    3. C. 'Hello' . 'World';
    4. D. 'Hello' u0026 'World';
    5. E. join('Hello', 'World');
  9. Superglobal Variables

    Which PHP superglobal variable is used to access form data sent via the HTTP POST method?

    1. A. $_COOKIE
    2. B. $_POST
    3. C. $_SERVER
    4. D. $_SESSION
    5. E. $GLOBALS
  10. PHP and Database Interaction

    Which of the following is typically used to connect PHP to a database when building dynamic web pages?

    1. A. file_connect()
    2. B. mysql_connect()
    3. C. data_link()
    4. D. db_connecter()
    5. E. connectSQL()