Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you define an empty array in PHP?
1) $array = array();
2) $array = [];
3) $array = array()
4) All of the above
Answer : Option 4
Which function is used to delete a file in PHP?
1) unlink()
2) delete()
3) remove()
4) file_delete()
Answer : Option 1
Which of the following is used to check if a file exists in PHP?
1) file_exists()
2) is_file()
3) file_check()
4) file_exist()
Answer : Option 1
How do you create an associative array in PHP?
1) $array = array("key1" => "value1", "key2" => "value2");
2) $array = array("value1", "value2");
3) $array = ["value1", "value2"];
4) $array = array("value1" => "key1", "value2" => "key2");
Answer : Option 1
What is the purpose of the `empty()` function in PHP?
1) To check if a variable is empty
2) To check if a variable is set
3) To check if a variable is not empty
4) To check if a variable is null
Answer : Option 1
How do you round a number to the nearest integer in PHP?
1) round()
2) ceil()
3) floor()
4) round_off()
Answer : Option 1
How do you set a session variable in PHP?
1) $_SESSION['var'] = "value";
2) session_set('var', "value");
3) session_start('var', "value");
4) set_session('var', "value");
Answer : Option 1
Which function is used to calculate the MD5 hash of a string in PHP?
1) md5()
2) hash_md5()
3) calculate_md5()
4) md5_hash()
Answer : Option 1
How do you get the type of a variable in PHP?
1) gettype()
2) type()
3) get_var_type()
4) var_type()
Answer : Option 1
Which function is used to check if a variable is an integer in PHP?
1) is_int()
2) is_integer()
3) is_numeric()
4) Both A and B
Answer : Option 4