Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
Which function is used to search for a string within another string in PHP?
1) strpos()
2) strstr()
3) search_str()
4) findstr()
Answer : Option 1
How can you create an array in PHP?
1) $array = array();
2) $array = [];
3) $array = array()
4) All of the above
Answer : Option 4
What is the default file extension for PHP files?
1) .html
2) .xml
3) .php
4) .ph
Answer : Option 3
How do you define a constant in PHP?
1) const NAME = "value";
2) define("NAME", "value");
3) constant NAME = "value";
4) define NAME = "value";
Answer : Option 2
Which function is used to send a raw HTTP header in PHP?
1) header()
2) send_header()
3) http_header()
4) raw_header()
Answer : Option 1
What is the output of the following code: echo (3 > 2) ? "Yes" : "No";
1) Yes
2) No
3) Error
4) Nothing
Answer : Option 1
Which function is used to sort an array in descending order?
1) sort()
2) rsort()
3) krsort()
4) asort()
Answer : Option 2
What will be the output of the following code: echo "10" + "5";
1) 105
2) 15
3) Error
4) 10+5
Answer : Option 2
Which of the following is the correct way to open a file in PHP?
1) fopen("filename", "r");
2) openfile("filename", "read");
3) file_open("filename", "r");
4) fileopen("filename", "read");
Answer : Option 1
What is the output of the following code: $x = 5; echo $x++;
1) 5
2) 6
3) Error
4) Nothing
Answer : Option 1