Learn PHP MCQs

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

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

1) Splits a string by a specified delimiter

2) Combines two strings

3) Removes whitespace from a string

4) Joins an array into a string

Answer : Option 1

How do you write a multi-line string in PHP?

1) Using heredoc syntax

2) Using a single-quoted string

3) Using a double-quoted string

4) Using a triple-quoted string

Answer : Option 1

Which function is used to get the keys of an array in PHP?

1) array_keys()

2) array_key()

3) key()

4) get_keys()

Answer : Option 1

How can you delete a cookie in PHP?

1) Set the cookie expiration time to a past date

2) Delete the cookie file

3) Remove the cookie from $_COOKIE

4) Unset the cookie variable

Answer : Option 1

Which function is used to return the current script’s filename in PHP?

1) basename(__FILE__)

2) filename()

3) get_filename()

4) get_file()

Answer : Option 1

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

1) Returns a portion of a string

2) Splits a string

3) Replaces a substring

4) Combines two strings

Answer : Option 1

Which function is used to include a file only once in PHP?

1) include_once()

2) require_once()

3) Both A and B

4) None of the above

Answer : Option 3

How do you create a multidimensional array in PHP?

1) $array = array(array(), array());

2) $array = array();

3) $array = array(array(), array());

4) Both A and C

Answer : Option 4

How do you convert a string to uppercase in PHP?

1) strtoupper()

2) upper()

3) string_toupper()

4) string_upper()

Answer : Option 1

Which of the following is the correct way to define a constant in PHP?

1) define("CONSTANT", "value");

2) const CONSTANT = "value";

3) Both A and B

4) None of the above

Answer : Option 3