Learn PHP MCQs

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

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

1) Returns an array with values common to all arrays

2) Merges two arrays

3) Finds the difference between two arrays

4) None of the above

Answer : Option 1

Which of the following is used to check if a constant is defined?

1) defined()

2) constant_exists()

3) is_defined()

4) check_constant()

Answer : Option 1

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

1) Removes duplicate values from an array

2) Sorts an array

3) Finds unique values in an array

4) None of the above

Answer : Option 1

How do you find the number of elements in an array in PHP?

1) count()

2) sizeof()

3) length()

4) Both A and B

Answer : Option 4

Which function is used to parse a URL and return its components?

1) parse_url()

2) url_parse()

3) split_url()

4) url_split()

Answer : Option 1

How do you convert a string to an integer in PHP?

1) intval()

2) convert_to_int()

3) str_to_int()

4) parseInt()

Answer : Option 1

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

1) Filters elements of an array using a callback function

2) Removes null values from an array

3) Finds unique elements in an array

4) None of the above

Answer : Option 1

Which function is used to split a string by a delimiter?

1) explode()

2) split()

3) str_split()

4) break()

Answer : Option 1

How do you convert a string to uppercase in PHP?

1) strtoupper()

2) to_upper()

3) string_upper()

4) uppercase()

Answer : Option 1

What is the output of `echo 10 % 3;` in PHP?

1) 1

2) 3

3) 0

4) Error

Answer : Option 1