Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you convert a string into an array in PHP?
1) explode()
2) split()
3) str_split()
4) Both A and C
Answer : Option 4
How can you generate a unique ID in PHP?
1) uniqid()
2) uniqueid()
3) id_generate()
4) generate_unique_id()
Answer : Option 1
Which of the following functions is used to terminate script execution in PHP?
1) exit()
2) die()
3) end()
4) Both A and B
Answer : Option 4
Which function is used to format a timestamp into a human-readable date in PHP?
1) date()
2) timestamp()
3) strptime()
4) strftime()
Answer : Option 1
How do you check if a variable is set and is not NULL in PHP?
1) isset()
2) is_defined()
3) is_set()
4) isnull()
Answer : Option 1
What is the output of `echo 5 + "5";` in PHP?
1) 10
2) 55
3) An error
4) 5
Answer : Option 1
Which function is used to filter a variable with a specified filter in PHP?
1) filter_var()
2) filter()
3) var_filter()
4) filter_input()
Answer : Option 1
Which of the following can be used to loop through an array in PHP?
1) foreach
2) while
3) for
4) All of the above
Answer : Option 4
How do you read the contents of a file into a string in PHP?
1) file_get_contents()
2) fread()
3) read_file()
4) file_read()
Answer : Option 1
What does the `session_start()` function do in PHP?
1) Starts a new session or resumes an existing session
2) Starts a new session only
3) Resumes an existing session only
4) Ends the current session
Answer : Option 1