Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle exceptions in PHP?
1) Using try-catch blocks
2) Using if-else statements
3) Using error handling functions
4) None of the above
Answer : Option 1
Which function is used to create a directory in PHP?
1) mkdir()
2) create_dir()
3) dir_create()
4) make_dir()
Answer : Option 1
How do you calculate the absolute value of a number in PHP?
1) abs()
2) absolute()
3) get_abs()
4) calc_abs()
Answer : Option 1
What does the `array_shift()` function do in PHP?
1) Removes the first element from an array
2) Adds an element to the beginning of an array
3) Removes the last element from an array
4) Adds an element to the end of an array
Answer : Option 1
How do you remove all HTML tags from a string in PHP?
1) strip_tags()
2) remove_html()
3) html_remove()
4) strip_html()
Answer : Option 1
Which function is used to create an array from a CSV file in PHP?
1) fgetcsv()
2) csv_to_array()
3) import_csv()
4) file_to_array()
Answer : Option 1
What is the output of `echo (int) "15.7abc";` in PHP?
1) 15
2) 16
3) 15.7
4) Error
Answer : Option 1
How do you access session variables in PHP?
1) Using `$_SESSION` superglobal array
2) Using `session()` function
3) Using `session_get()` function
4) Using `get_session()` function
Answer : Option 1
Which function is used to escape HTML entities in a string in PHP?
1) htmlspecialchars()
2) escape_html()
3) html_escape()
4) html_encode()
Answer : Option 1
How do you get the first element of an array in PHP?
1) Using `reset()`
2) Using `first()`
3) Using `array_first()`
4) Using `array_head()`
Answer : Option 1