Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `__clone` method in a PHP class?
1) To create a copy of an object
2) To compare two objects
3) To delete an object
4) To clone a class
Answer : Option 1
Which function is used to remove HTML tags from a string in PHP?
1) strip_tags()
2) remove_tags()
3) clean_html()
4) html_purify()
Answer : Option 1
How do you create an empty array in PHP?
1) $array = array();
2) $array = [];
3) $array = array()
4) All of the above
Answer : Option 4
Which function would you use to search for a pattern in a string in PHP?
1) preg_match()
2) preg_find()
3) pattern_search()
4) preg_search()
Answer : Option 1
How do you 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
What is the default maximum execution time for a PHP script?
1) 30 seconds
2) 60 seconds
3) 120 seconds
4) No limit
Answer : Option 1
Which of the following is a way to force strict mode in PHP?
1) declare(strict_types=1);
2) declare(strict_types=1)
3) use strict_mode();
4) set_strict_mode();
Answer : Option 2
How do you check if a file was uploaded successfully in PHP?
1) $_FILES['file']['error'] == UPLOAD_ERR_OK
2) $_FILES['file']['status'] == UPLOAD_OK
3) file_exists($_FILES['file']['tmp_name'])
4) check_upload($_FILES['file'])
Answer : Option 1
How can you compare two strings in PHP without considering case?
1) strcasecmp()
2) strcmp()
3) strtolower()
4) strcmplower()
Answer : Option 1
Which function is used to pause the execution of a script for a specified number of microseconds?
1) usleep()
2) sleep()
3) pause()
4) wait()
Answer : Option 1