1. Which PHP function is used to check if a variable is an array?
Step-by-Step Explanation
is_array() specifically checks if a given variable is an array.
Answer: a) is_array() ✅
2. What is the purpose of the abstract keyword in PHP?
Step-by-Step Explanation
The abstract keyword is used to define abstract classes, which cannot be instantiated and may contain abstract methods that must be implemented by child classes.
Answer: c) To define a class that cannot be instantiated. ✅
3. Which PHP function is used to sort an array in ascending order by value, maintaining index association?
Step-by-Step Explanation
asort() sorts an array in ascending order by value and maintains the index association. sort() does not maintain index association.
Answer: b) asort() ✅
4. What does the final keyword in PHP prevent?
Step-by-Step Explanation
The final keyword, when applied to a method, prevents it from being overridden by child classes, and when applied to a class, it prevents the class from being inherited.
Answer: c) Function overriding. ✅
5. Which PHP function is used to calculate the length of a string?
Step-by-Step Explanation
strlen() returns the length of a string.
Answer: a) strlen() ✅
6. What is the purpose of the trait keyword in PHP?
Step-by-Step Explanation
Traits are used to reuse code in multiple classes independently of the inheritance hierarchy.
Answer: b) To reuse code in multiple classes independently of inheritance. ✅
7. Which PHP function is used to replace all occurrences of a search string with a replacement string?
Step-by-Step Explanation
str_replace() replaces all occurrences of a search string with a replacement string.
Answer: d) str_replace() ✅
8. What does the static keyword in PHP indicate?
Step-by-Step Explanation
The static keyword indicates that a property or method belongs to the class itself, rather than an instance of the class.
Answer: c) A property or method that belongs to the class itself, not an instance. ✅
9. Which PHP function is used to retrieve the value of an environment variable?
Step-by-Step Explanation
getenv() retrieves the value of an environment variable. $_ENV is also an array that contains environment variables.
Answer: a) getenv() ✅
10. What is the purpose of the try...catch block in PHP?
Step-by-Step Explanation
The try...catch block is used to handle exceptions, allowing you to gracefully manage errors.
Answer: d) To handle exceptions. ✅
11. Which PHP function is used to encode a URL?
Step-by-Step Explanation
urlencode() encodes a URL string.
Answer: b) urlencode() ✅
12. What does the protected access modifier in PHP indicate?
Step-by-Step Explanation
protected members are accessible within the class and its subclasses.
Answer: c) Accessible within the class and its subclasses. ✅
13. Which PHP function is used to format a date and time?
Step-by-Step Explanation
date() formats a date and time according to a specified format.
Answer: a) date() ✅
14. What is the purpose of the __construct() method in a PHP class?
Step-by-Step Explanation
__construct() is a special method called when an object is created, used to initialize object properties.
Answer: b) To initialize object properties. ✅
15. Which PHP function is used to retrieve the keys of an array?
Step-by-Step Explanation
array_keys() returns all the keys of an array.
Answer: b) array_keys() ✅
16. What is the purpose of the __destruct() method in a PHP class?
Step-by-Step Explanation
__destruct() is a special method called when an object is destroyed.
Answer: b) To destroy an object. ✅
17. Which PHP function is used to filter elements of an array using a callback function?
Step-by-Step Explanation
array_filter() filters elements of an array using a callback function.
Answer: c) array_filter() ✅
18. What does the clone keyword in PHP do?
Step-by-Step Explanation
The clone keyword creates a copy of an object.
Answer: b) Creates a copy of an object. ✅
19. Which PHP function is used to get the current working directory?
Step-by-Step Explanation
getcwd() returns the current working directory.
Answer: d) getcwd() ✅
20. What is the purpose of the declare(strict_types=1); directive in PHP?
Step-by-Step Explanation
declare(strict_types=1); enables strict type checking for function calls and return statements.