Here are the collections of the top 20 MCQ questions on arrays in PHP which includes multiple-choice questions on fundamentals of arrays in PHP. It includes objective questions on different functions used for testing an array, outputting and printing an array, adding and removing array elements, locating, searching array keys, and array values and traversing arrays in PHP.
Read Also: 20 Best MCQ Questions on PHP Functions
1. State whether the following statements about arrays in PHP are True or False.
i. PHP doesn’t require to assign a size to an array at creation time.
ii. PHP require to declare the array before using it.
iii. Each element on the PHP array are referenced by denoting the element between a pair of square brackets.
A) i-False, ii-True, iii-True
B) i-False, ii-True, iii-False
C) i-True, ii-True, iii-True
D) i-True, ii-False, iii-True
2. The … function determines whether the variable is an array, returning TRUE if it is and FALSE otherwise.
A) array()
B) is_array()
C) check_array()
D) array_check()
3. … function allows us to easily display array contents using the same formatting syntax used by the printf().
i. vprint()
ii.vprintf()
iii. sprintf()
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii
4. The … function accepts a variable and sends its contents to standard output, returning TRUE on success and FALSE otherwise.
A) print_r
B) print_v
C) print_s
D) print_o
5. The … function adds elements to the front of the array.
A) array_push()
B) array_shift()
C) array_unshift()
D) array_front()
6. The … function adds a value to the end of an array.
A) array_push()
B) array_shift()
C) array_unshift()
D) array_end()
7. The … function removes and returns the first item found in an array.
A) array_push()
B) array_shift()
C) array_unshift()
D) array_first()
8. The … function removes and returns the last element from an array.
A) array_push()
B) array_shift()
C) array_pop()
D) array_last()
9. The … function searches an array for a specific value, returning TRUE if the value is found and FALSE otherwise.
A) in_array_value()
B) in_array()
C) array_search()
D) array_value()
10. The … function returns TRUE if the specified key is found in an array and FALSE otherwise.
A) array_values()
B) array_keys()
C) array_search()
D) array_key_exists()
11. The … function searches on the array for a specified value, returning its key if located and FALSE otherwise.
A) array_values()
B) array_keys()
C) array_search()
D) array_key_exists()
12. The … function returns an array consisting of all keys located in an array.
A) keys_array()
B) array_keys()
C) array_search()
D) array_key_exists()
13. The … function returns all values located in an array, automatically providing numeric indexes for the returned array.
A) numeric_array()
B) array_indexes()
C) array_search()
D) array_values()
14. The … function returns the key located at the current pointer position of the provided array.
A) key()
B) current_key()
C) array_search()
D) current_key_exists()
15. The … function returns the array value residing at the current pointer position of the array.
A) current()
B) current_key()
C) each_key()
D) current_key_exists()
16. The … function returns the current key /value pair from the array and advances the pointer on position.
A) current()
B) current_key()
C) each_key()
D) each()
17. The … function returns the array value residing at the position immediately following that of the current array pointer.
A) current()
B) current_array()
C) next_array()
D) next()
18. The … function returns the array value residing at the location preceding the current pointer location, or FALE if the pointer resides at the first position in the array.
A) reset()
B) preceding_array()
C) prev_array()
D) prev()
19. … is used when you need to review or manipulate an array multiple times within a script.
A) review()
B) reset_array()
C) reset()
D) manipulate()
20. The function moves the pointer to the last position of an array.
A) end_array()
B) last_array()
C) end()
D) last()
Answers:
- D) i-True, ii-False, iii-True
- B) is_array()
- C) i and iii only
- A) print_r
- C) array_unshift()
- A) array_push()
- B) array_shift()
- C) array_pop()
- B) in_array()
- D) array_key_exists()
- C) array_search()
- B) array_keys()
- D) array_values()
- A) key()
- A) current()
- D) each()
- D) next()
- D) prev()
- C) reset()
- C) end()
Read Next: 20 Objective Questions on Arrays in PHP Part-2