Learn PHP MCQs

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

Which function is used to replace the first occurrence of a substring in a string in PHP?

1) str_replace() with limit parameter

2) substr_replace()

3) str_ireplace()

4) None of the above

Answer : Option 1

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

1) Establishes a connection to a MySQL database

2) Disconnects from a MySQL database

3) Executes a MySQL query

4) None of the above

Answer : Option 1

How do you check if a variable is an array in PHP?

1) Using `is_array()`

2) Using `array_check()`

3) Using `check_array()`

4) Using `var_is_array()`

Answer : Option 1

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

1) uniqid()

2) unique_id()

3) generate_id()

4) create_id()

Answer : Option 1

How do you encrypt data in PHP?

1) Using `openssl_encrypt()`

2) Using `encrypt()`

3) Using `hash()`

4) Using `encode()`

Answer : Option 1

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

1) Extracts a portion of an array

2) Slices an array into two

3) Removes a part of an array

4) Merges two arrays

Answer : Option 1

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

1) Using `end()`

2) Using `last()`

3) Using `array_last()`

4) Using `array_end()`

Answer : Option 1

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

1) 1

2) 3

3) 0

4) Error

Answer : Option 1

How do you connect to a MySQL database using PDO in PHP?

1) Using `new PDO()`

2) Using `pdo_connect()`

3) Using `connect()`

4) Using `new mysqli()`

Answer : Option 1

Which function is used to get the current timestamp in PHP?

1) time()

2) timestamp()

3) current_time()

4) now()

Answer : Option 1