Create New Post

PHP MCQs - 4

  1. Which of the following PHP superglobals contains information about files uploaded to the server?
  • A) $_FILES
  • B) $_POST
  • C) $_GET
  • D) $_SESSION

Answer: A) $_FILES

  1. What is the purpose of the htmlspecialchars() function in PHP?
  • A) Converts special characters to HTML entities
  • B) Escapes special characters in a string to prevent XSS attacks
  • C) Removes HTML tags from a string
  • D) Converts HTML entities to special characters

Answer: B) Escapes special characters in a string to prevent XSS attacks

  1. Which of the following is not a valid method of including PHP code within HTML?
  • A) <?php ... ?>
  • B) <? ... ?>
  • C) <?php ... ?>
  • D) <?= ... ?>

Answer: B) <? ... ?>

  1. What is the purpose of the unset() function in PHP?
  • A) Deletes a file from the server
  • B) Removes a session variable
  • C) Destroys the current session
  • D) Removes a variable or array element

Answer: D) Removes a variable or array element

  1. Which PHP function is used to format a timestamp into a more readable date and time?
  • A) date()
  • B) time()
  • C) mktime()
  • D) strtotime()

Answer: A) date()

  1. What does the array_keys() function in PHP do?
  • A) Returns all the values of an array
  • B) Returns all the keys of an array
  • C) Returns the number of elements in an array
  • D) Reverses the order of elements in an array

Answer: B) Returns all the keys of an array

  1. What is the output of the following code snippet?
echo strlen("Hello World!"); 
  • A) 11
  • B) 12
  • C) 10
  • D) 13

Answer: C) 11

  1. Which of the following is used to declare a constant in PHP within a class?
  • A) const
  • B) define()
  • C) constant()
  • D) var()

Answer: A) const

  1. What is the correct way to check if a function exists in PHP?
  • A) function_exists()
  • B) exists_function()
  • C) check_function()
  • D) is_function()

Answer: A) function_exists()

  1. What does the array_pop() function in PHP do?
  • A) Adds an element to the end of an array
  • B) Removes the first element from an array
  • C) Removes the last element from an array
  • D) Returns the last element of an array

Answer: C) Removes the last element from an array

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

98118