Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of `echo 5 + "5 cars";` in PHP?
1) 10
2) 55 cars
3) Error
4) 5 cars
Answer : Option 1
How do you end a PHP script?
1) exit()
2) end()
3) terminate()
4) stop()
Answer : Option 1
Which function is used to determine if a string starts with a specific substring?
1) substr()
2) strpos()
3) strstr()
4) str_start()
Answer : Option 2
How do you get the number of elements in an array?
1) count()
2) sizeof()
3) length()
4) Both A and B
Answer : Option 4
What does the `addslashes()` function do in PHP?
1) Adds backslashes before certain characters
2) Escapes HTML entities
3) Adds slashes to a string
4) Removes backslashes from a string
Answer : Option 1
How do you get the current URL in PHP?
1) $_SERVER['REQUEST_URI']
2) $_SERVER['HTTP_HOST']
3) $_SERVER['URL']
4) $_SERVER['CURRENT_URL']
Answer : Option 1
What is the difference between `include()` and `require()` in PHP?
1) Require() stops script execution if the file is not found, include() does not
2) Include() is faster
3) Require() is for external files only
4) There is no difference
Answer : Option 1
How do you remove an element from an array in PHP?
1) unset()
2) remove()
3) delete()
4) unset_array()
Answer : Option 1
What does `isset()` function do?
1) Checks if a variable is set and is not NULL
2) Checks if a variable is empty
3) Checks if a variable is an array
4) Checks if a variable is a string
Answer : Option 1
How can you convert an object to an array in PHP?
1) get_object_vars()
2) object_to_array()
3) convert_to_array()
4) serialize()
Answer : Option 1