Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you specify a default value for a function parameter in PHP?
1) function myFunction($param = "default")
2) function myFunction($param default "default")
3) function myFunction($param == "default")
4) function myFunction(default $param = "default")
Answer : Option 1
Which function is used to change the owner of a file in PHP?
1) chown()
2) chmod()
3) file_owner()
4) change_owner()
Answer : Option 1
How do you create a constant array in PHP?
1) define("CONSTANT", array(1, 2, 3));
2) const CONSTANT = array(1, 2, 3);
3) Both A and B
4) Cannot define an array as constant
Answer : Option 3
Which function is used to find the first occurrence of a string inside another string in PHP?
1) strpos()
2) strstr()
3) strchr()
4) strpos_find()
Answer : Option 1
Which PHP function converts an array to a string with a specified delimiter?
1) implode()
2) join()
3) explode()
4) merge()
Answer : Option 1
How do you open a file for writing in PHP, and if it doesn’t exist, create it?
1) fopen($filename, "w")
2) fopen($filename, "a")
3) fopen($filename, "x")
4) fopen($filename, "c")
Answer : Option 1
Which of the following functions can be used to send headers to the browser in PHP?
1) header()
2) send_headers()
3) browser_headers()
4) send_response()
Answer : Option 1
How can you remove the leading and trailing spaces from a string in PHP?
1) trim()
2) strip()
3) ltrim()
4) rtrim()
Answer : Option 1
Which of the following is used to calculate the length of an array in PHP?
1) count()
2) sizeof()
3) length()
4) Both A and B
Answer : Option 4
How do you prevent a form from resubmitting when the page is refreshed in PHP?
1) Use header("Location: URL") after form processing
2) Use exit() after form processing
3) Use die() after form processing
4) Use break after form processing
Answer : Option 1