Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
Which function is used to get the length of an array?
1) count()
2) length()
3) array_length()
4) array_count()
Answer : Option 1
How do you find the maximum value in an array in PHP?
1) max()
2) maximum()
3) array_max()
4) array_maximum()
Answer : Option 1
Which function is used to check if a file exists in PHP?
1) file_exists()
2) is_file()
3) check_file()
4) find_file()
Answer : Option 1
How do you convert an array to a string in PHP?
1) implode()
2) explode()
3) join()
4) array_to_string()
Answer : Option 1
Which function is used to find the largest number in a list of arguments?
1) max()
2) maximum()
3) array_max()
4) array_maximum()
Answer : Option 1
How do you terminate the script execution in PHP?
1) terminate()
2) exit()
3) end()
4) stop()
Answer : Option 2
What is the correct way to include a file only if it has not been included before?
1) include_once()
2) require_once()
3) include_if()
4) require_if()
Answer : Option 1
Which function is used to set a cookie in PHP?
1) setcookie()
2) createcookie()
3) makecookie()
4) cookie()
Answer : Option 1
How do you create an associative array in PHP?
1) $array = array("key1" => "value1", "key2" => "value2");
2) $array = ["key1" => "value1", "key2" => "value2"];
3) $array = associative("key1", "value1", "key2", "value2");
4) Both A and B
Answer : Option 4
How do you sort an array by values in descending order?
1) sort()
2) rsort()
3) krsort()
4) arsort()
Answer : Option 4