Learn PHP MCQs

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

How do you add an element to the beginning of an array in PHP?

1) array_unshift()

2) array_shift()

3) array_push()

4) array_add()

Answer : Option 1

How can you determine 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 can be used to replace a substring within a string in PHP?

1) str_replace()

2) replace_string()

3) replace()

4) string_replace()

Answer : Option 1

How do you get the last element of an array in PHP?

1) end()

2) last()

3) array_end()

4) array_last()

Answer : Option 1

Which of the following is used to count the number of elements in an array in PHP?

1) count()

2) sizeof()

3) length()

4) Both A and B

Answer : Option 4

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

1) strpos($string, $substring) === 0

2) substr($string, 0, strlen($substring)) == $substring

3) Both A and B

4) None of the above

Answer : Option 3

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

1) count()

2) size()

3) num_elements()

4) get_count()

Answer : Option 1

Which function is used to generate a unique ID in PHP?

1) uniqid()

2) generate_id()

3) unique_id()

4) create_id()

Answer : Option 1

How do you create a cookie in PHP?

1) setcookie()

2) create_cookie()

3) make_cookie()

4) cookie()

Answer : Option 1

Which function is used to read the contents of a file into a string in PHP?

1) file_get_contents()

2) fread()

3) read_file()

4) file_read()

Answer : Option 1