Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you remove an element from an array by its value in PHP?
1) unset()
2) array_remove()
3) remove()
4) delete()
Answer : Option 1
What is the output of `echo "Hello" . " World";` in PHP?
1) Hello World
2) HelloWorld
3) Hello World
4) Error
Answer : Option 1
Which function is used to perform a regular expression match in PHP?
1) preg_match()
2) match()
3) regex_match()
4) preg_search()
Answer : Option 1
How do you convert a string to an array in PHP?
1) explode()
2) str_split()
3) split()
4) array()
Answer : Option 1
What is the purpose of the `ob_start()` function in PHP?
1) Starts output buffering
2) Clears the output buffer
3) Flushes the output buffer
4) None of the above
Answer : Option 1
How do you set the maximum execution time of a script in PHP?
1) set_time_limit()
2) max_execution_time()
3) time_limit()
4) set_execution_time()
Answer : Option 1
What does the `base64_encode()` function do in PHP?
1) Encodes data with MIME base64
2) Decodes data encoded with MIME base64
3) Encodes data with URL base64
4) None of the above
Answer : Option 1
Which of the following is a valid method for connecting to a MySQL database in PHP?
1) mysqli_connect()
2) mysql_connect()
3) connect_mysql()
4) mysql_connect()
Answer : Option 1
What is the purpose of the `__toString()` method in PHP?
1) Converts an object to a string
2) Returns the object class name
3) Converts a string to an object
4) None of the above
Answer : Option 1
How do you set a cookie in PHP?
1) setcookie()
2) set_cookie()
3) create_cookie()
4) cookie_set()
Answer : Option 1