Learn PHP MCQs

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

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

1) Repeats a string a specified number of times

2) Replaces a substring within a string

3) Removes a substring from a string

4) Splits a string into an array

Answer : Option 1

Which function is used to set the internal pointer of an array to its first element in PHP?

1) reset()

2) current()

3) first()

4) array_first()

Answer : Option 1

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

1) 5

2) 32

3) 3

4) Error

Answer : Option 1

How do you remove duplicate values from an array in PHP?

1) array_unique()

2) array_diff()

3) array_filter()

4) array_remove_duplicates()

Answer : Option 1

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

1) Removes whitespace from both sides of a string

2) Removes all whitespace from a string

3) Removes only leading whitespace from a string

4) Removes only trailing whitespace from a string

Answer : Option 1

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

1) count()

2) sizeof()

3) array_size()

4) len()

Answer : Option 1

What is the output of `echo (0 == "");` in PHP?

1) true

2) false

3) Error

4) NULL

Answer : Option 1

How do you check if a string starts with a specific substring in PHP?

1) strpos()

2) strstr()

3) str_starts_with()

4) strstr_starts()

Answer : Option 1

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

1) Extracts a portion of an array

2) Removes elements from an array

3) Replaces elements in an array

4) Combines two or more arrays

Answer : Option 1

How do you generate a unique file name in PHP?

1) Using `uniqid()` with a prefix

2) Using `md5()` with a prefix

3) Using `sha1()` with a prefix

4) Using `rand()` with a prefix

Answer : Option 1