Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you convert an array to a string in PHP?
1) implode()
2) join()
3) stringify()
4) convert_array()
Answer : Option 1
Which of the following is the correct way to print all the elements of an array in PHP?
1) print_r($array)
2) echo($array)
3) echo array($array)
4) print($array)
Answer : Option 1
How do you generate a unique session ID in PHP?
1) session_id()
2) session_start()
3) session_generate_id()
4) session_new()
Answer : Option 1
How do you format a number with grouped thousands in PHP?
1) number_format()
2) format_number()
3) num_format()
4) format()
Answer : Option 1
How do you check if a variable is a float in PHP?
1) is_float()
2) is_double()
3) is_real()
4) Both A and B
Answer : Option 4
Which function is used to create an array containing a range of elements in PHP?
1) range()
2) array_fill()
3) array()
4) fill_array()
Answer : Option 1
Which of the following is used to replace all occurrences of a search string with a replacement string in PHP?
1) str_replace()
2) str_replace_all()
3) replace()
4) string_replace()
Answer : Option 1
What does the `switch` statement do in PHP?
1) Executes a block of code among multiple options based on a condition
2) Selects a case
3) Runs a loop
4) Creates a function
Answer : Option 1
How do you add an element to an array in PHP?
1) array_push()
2) push()
3) add()
4) array_add()
Answer : Option 1
Which function is used to escape a string for use in a MySQL query in PHP?
1) mysqli_real_escape_string()
2) mysql_real_escape_string()
3) escape()
4) escape_string()
Answer : Option 1