Learn PHP MCQs

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

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

1) Checks if a key exists in an array

2) Checks if a value exists in an array

3) Checks if an element exists in an array

4) Checks if an array is empty

Answer : Option 1

How do you retrieve the value of a cookie in PHP?

1) $_COOKIE

2) get_cookie()

3) cookie_get()

4) retrieve_cookie()

Answer : Option 1

What is the output of `echo 10 == "10";` in PHP?

1) true

2) false

3) Error

4) None of the above

Answer : Option 1

Which of the following is used to create a MySQL database in PHP?

1) mysqli_query()

2) mysqli_db_create()

3) create_database()

4) db_create()

Answer : Option 1

How do you destroy a session in PHP?

1) session_destroy()

2) session_end()

3) end_session()

4) destroy_session()

Answer : Option 1

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

1) Adds one or more elements to the end of an array

2) Removes the last element of an array

3) Adds one or more elements to the beginning of an array

4) Removes the first element of an array

Answer : Option 1

What does the `__construct()` method do in PHP?

1) Initializes an object when it is created

2) Destroys an object when it is no longer needed

3) Creates a new class

4) None of the above

Answer : Option 1

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

1) intval()

2) to_int()

3) str_to_int()

4) convert_to_int()

Answer : Option 1

Which function is used to remove whitespace or other characters from the end of a string in PHP?

1) rtrim()

2) ltrim()

3) trim()

4) chop()

Answer : Option 1

How do you retrieve the keys of an array in PHP?

1) array_keys()

2) get_keys()

3) keys()

4) retrieve_keys()

Answer : Option 1