PHP Questions and Answers Part-4

1. Why trim() function is used in php?
a) to remove whitespaces
b) to remove lowercase alphabet
c) to remove uppercase alphabet
d) to remove underscore

Answer: a
Explanation: This trim() function allows us to remove whitespaces or strings from both sides of a string.

2. Which one of the following property scopes is not supported by PHP?
a) final
b) public
c) static
d) friendly

Answer: d
Explanation: PHP supports five class property scopes: public, private, protected, final and static.

3. Which one of the following functions is used to determine object type?
a) obj_type()
b) type()
c) is_a()
d) is_obj()

Answer: c
Explanation: The is_a() function returns true if object belongs to a class type or if it belongs to a class that is a child of that class. Or else false is returned.

4. Which is true about var_dump() function?
a) var_dump() loops infinitely
b) var_dump() cuts off loop afetr getting same element two times
c) var_dump() cuts off loop after getting the same element three times
d) var_dump() cuts off loop after getting the same element five times

Answer: c
Explanation: var_dump() cuts off loop after getting the same element three times is true about var_dump() function.

5. Which one of the following is the right way to define a constant?
a) constant PI = “3.1415?;
b) const $PI = “3.1415?;
c) constant PI = ’3.1415';
d) const PI = ’3.1415';

Answer: d
Explanation: Class constants are created like: const NAME = ‘VALUE’;

6. The ________ function compares the two strings s1 and s2, ignoring the case of the characters.
a) strtolower()
b) toLowerCase()
c) strcasecmp()
d) lc()

Answer: c
Explanation: The strcasecmp() function compares the two strings s1 and s2, ignoring the case of the characters.

7. Which one of the following should not be used while sending passwords or other sensitive information?
a) GET
b) POST
c) NEXT
d) REQUEST

Answer: a
Explanation: Because the data is visible to everyone.

8. Which type of string can processes special characters inside quotes?
a) single quote string
b) double quote string
c) Both A and B
d) None of the above

Answer: b
Explanation: double-quote strings in PHP is capable of processing special characters.

9. When you use the $_POST variable to collect data, the data is visible to
a) none
b) only you
c) everyone
d) selected few

Answer: b
Explanation: The information sent from a form with the method POST is invisible to others i.e., all names/values are embedded within the body of the HTTP request.

10. How many value/values does Boolean data type hold?
a) 1
b) 2
c) 3
d) 4

Answer: b
Explanation: Boolean: Hold only two values, either TRUE or FALSE.