Learn PHP MCQs

Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.

What is the output of `echo 10 == "10";`?

1) 1

2) 0

3) True

4) False

Answer : Option 1

Which of the following is the correct way to define a multi-line string in PHP?

1) Using heredoc syntax

2) Using single quotes

3) Using double quotes

4) Using backticks

Answer : Option 1

What does the `session_destroy()` function do in PHP?

1) Destroys all data associated with the current session

2) Removes a session variable

3) Ends the session

4) Both A and C

Answer : Option 4

How do you convert a string to lowercase in PHP?

1) strtolower()

2) lower()

3) string_lower()

4) to_lower()

Answer : Option 1

Which function is used to send an HTTP header in PHP?

1) header()

2) set_header()

3) http_header()

4) send_header()

Answer : Option 1

How do you get the file extension of a file in PHP?

1) pathinfo()

2) get_extension()

3) file_ext()

4) None of the above

Answer : Option 1

What does the `array_sum()` function do in PHP?

1) Returns the sum of the values in an array

2) Finds the maximum value in an array

3) Merges two arrays

4) Returns the first value in an array

Answer : Option 1

Which of the following is the correct way to open a file for writing in PHP?

1) fopen($filename, "w")

2) fopen($filename, "r")

3) fopen($filename, "a")

4) fwrite($filename)

Answer : Option 1

How do you get the current script name in PHP?

1) $_SERVER['PHP_SELF']

2) $_SERVER['SCRIPT_NAME']

3) $_SERVER['CURRENT_SCRIPT']

4) $_SERVER['SCRIPT_SELF']

Answer : Option 1

What is the output of `echo "2" + 2;` in PHP?

1) 4

2) 22

3) Error

4) None of the above

Answer : Option 1