Learn PHP MCQs

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

How do you remove all leading whitespace from a string?

1) ltrim()

2) rtrim()

3) trim()

4) strip()

Answer : Option 1

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

1) Converts a variable into a storable representation

2) Encodes a string to JSON

3) Compresses a string

4) None of the above

Answer : Option 1

Which function is used to perform case-insensitive string comparison in PHP?

1) strcasecmp()

2) strcmpi()

3) strcompare()

4) compare()

Answer : Option 1

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

1) explode()

2) split()

3) str_split()

4) array()

Answer : Option 1

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

1) Returns all the values of an array

2) Returns all the keys of an array

3) Finds a value in an array

4) Returns the first value in an array

Answer : Option 1

Which of the following functions is used to combine the keys and values from two arrays into one associative array?

1) array_combine()

2) array_merge()

3) array_key_value()

4) combine_arrays()

Answer : Option 1

How do you get the current line number in a PHP script?

1) __LINE__

2) __CURRENT_LINE__

3) line_number()

4) None of the above

Answer : Option 1

Which of the following functions is used to find the length of an array?

1) count()

2) sizeof()

3) array_length()

4) Both A and B

Answer : Option 4

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

1) Applies a user-defined function to each element of an array

2) Sorts an array

3) Merges two arrays

4) Splits an array into smaller arrays

Answer : Option 1

How do you convert a string to a floating-point number in PHP?

1) floatval()

2) str_to_float()

3) convert_to_float()

4) to_float()

Answer : Option 1