Learn PHP MCQs

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

What is the purpose of the `implode()` function in PHP?

1) Joins array elements into a string

2) Splits a string into an array

3) Converts an object to a string

4) None of the above

Answer : Option 1

Which function is used to format a string in PHP?

1) sprintf()

2) printf()

3) format()

4) string_format()

Answer : Option 1

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

1) Checks if a value exists in an array

2) Finds the index of a value in an array

3) Checks if an array is empty

4) Merges two arrays

Answer : Option 1

Which of the following is used to create an empty object in PHP?

1) (object)array()

2) new stdClass()

3) empty()

4) new object()

Answer : Option 2

How do you find the position of a substring in a string?

1) strpos()

2) strstr()

3) substr()

4) find()

Answer : Option 1

Which of the following functions is used to change the case of all characters in a string to lowercase?

1) strtolower()

2) tolower()

3) str_lower()

4) string_lower()

Answer : Option 1

What is the purpose of the `array_diff()` function in PHP?

1) Computes the difference between two arrays

2) Merges two arrays

3) Finds common elements between two arrays

4) None of the above

Answer : Option 1

How do you create an instance of a class in PHP?

1) new ClassName()

2) ClassName()

3) create ClassName()

4) instantiate ClassName()

Answer : Option 1

What does the `session_start()` function do?

1) Starts a new session or resumes an existing session

2) Creates a new session variable

3) Ends a session

4) None of the above

Answer : Option 1

Which function is used to find the maximum value in an array?

1) max()

2) maximum()

3) array_max()

4) get_max()

Answer : Option 1