Create New Post

PHP MCQs - 3

  1. What is the output of the following code snippet?
$a = 5;
$b = 10;
echo ($a > $b) ? "Greater" : "Smaller";
  • A) Greater
  • B) Smaller
  • C) Error
  • D) None of the above

Answer: B) Smaller

  1. Which of the following PHP functions is used to remove whitespace or other predefined characters from the right side of a string?
  • A) rtrim()
  • B) ltrim()
  • C) trim()
  • D) strip()

Answer: A) rtrim()

  1. What does the file_get_contents() function in PHP do?
  • A) Reads a file into a string
  • B) Writes data to a file
  • C) Checks if a file exists
  • D) Deletes a file

Answer: A) Reads a file into a string

  1. Which of the following is used to loop through all the values of an array in PHP?
  • A) foreach
  • B) for
  • C) while
  • D) do-while

Answer: A) foreach

  1. What is the output of the following code snippet?
$x = 10;
echo ++$x;
  • A) 9
  • B) 10
  • C) 11
  • D) Error

Answer: C) 11

  1. Which of the following is used to combine two arrays into one in PHP?
  • A) array_combine()
  • B) array_merge()
  • C) array_intersect()
  • D) array_diff()

Answer: B) array_merge()

  1. What is the default method for sending form data in PHP?
  • A) GET
  • B) POST
  • C) PUT
  • D) DELETE

Answer: B) POST

  1. Which of the following is used to redirect the user to another page in PHP?
  • A) redirect()
  • B) header()
  • C) refresh()
  • D) goto()

Answer: B) header()

  1. What does the str_replace() function in PHP do?
  • A) Replaces all occurrences of a search string with another string
  • B) Reverses a string
  • C) Trims whitespace from both ends of a string
  • D) Returns the length of a string

Answer: A) Replaces all occurrences of a search string with another string

  1. What does the $_SESSION superglobal variable in PHP store?
  • A) Server settings
  • B) User session data
  • C) Cookies
  • D) POST data

Answer: B) User session data

Comments

Leave a Reply

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

87139