PHP Arrays MCQ Questions and Answers

What is an array in PHP?

Answer: An array is a collection of data values.

Which function is used to remove duplicate elements from an array in PHP?

Answer: array_unique() function is used to remove duplicate elements from an array in PHP.

How to check if given variable is array or not in PHP?

Answer: is_array() function is used to check if given variable is array or not.

What is the use of count() function in PHP?

Answer: count() in PHP returns the size of an array and hence it is used for the same.

What is the purpose of asort() fubction in PHP?

Answer: asort() function in PHP is used to sort an array in ascending order on values without changing the indexes.

What is the purpose of array_splice() function?

Answer: array_splice() function in PHP is used to remove or insert elements in an array.
Syntax:
$removed = array_splice(array,start[,length [,replacement]]);

What is an associative array in PHP?

Answer: Arrays that have strings as keys/indexs and that behave as two column tables. The first is the key which is used to access the value corresponding to it.

Give an example of associative array (PHP Code).

Answer: Example:
$student = arrray("Roll No" => 101, "Name" => "John", "Class" = > "FY");

Which function is used to create an array in PHP?

Answer: array() is used to create either an indexed lr associative array in PHP.

What is the use/purpose of array_filter() in PHP?

Answer: array_filter() function identifies a subset of an array based of its values. It calls a function for each element in an array and if the function returns true, corresponding element is added to filtered array.

PHP Arrays MCQ

What is an array?
Collection of data values
sequence of characters
sequence of strings
None of above
Which function is used to copy all the values from an array to the variables?
array_copy()
list()
variable_copy()
None of above
What is the syntax of array_slice() function?
$subset = array_slice(array, offset, length);
$subset = array_slice(array,length);
$subset = array_slice(array, offset);
None of the above
Which function is used to divide an array into smaller evenly sized arrays in PHP?
array_divide()
array_crop()
array_chunk()
None of the above
Which function is used to get keys of an array as an array in PHP?
keys()
array_keys()
array_values()
array_splice()
Which function is used to create local variables from an array having same names as keys in PHP?
compact()
extract()
array_variables()
array_variable_keys()
Which function is used to construct an array from variables in PHP?
extract()
compact()
create_array()
None of the above
Which function is used to merge two or more arrays together in PHP?
array_union()
array_diff()
array_sum()
array_merge()
Which two functions can be used to obtain union of two sets, with duplicates removed in PHP?
array_merge() and array_unique()
array_unique() and array_diff()
array_union() and array_diff()
None of the above
Which function in PHP is used to identify values from one array that are not present in others?
array_intersect()
array_diff()
array_sum()
None of the above
Which function is used to push element in an array in PHP?
array_push()
array_pop()
array_i()
None of the above
Which function is used to reverse the internal order of elements in an array in PHP?
array_shuffle()
array_reverse()
reverse()
None of the above
Which function is used to get a set of common elements from n number of arrays in PHP?
array_common()
array_intersect()
array_unique()
None of the above
Which function is used to sort array in ascending order by values in PHP?
asort()
arsort()
uasort()
uksort()
Which function is used to sort an array in descending order by values and then reassigning the indexes starting with 0 in PHP?
sort()
asort()
rsort()
ksort()
Which of the following is a valid array sorting function in PHP?
natasort()
natrsort()
natcaseasort()
natsort()
Which function is used to reverse the order of key value pair of each element in an array in PHP?
array_reverse_key_value()
array_flip()
reverse()
flip_keys()
Which function is used to solve multiple indexed arrays at once in PHP?
msort()
multisort()
array_msort()
array_multisort()
Which function is used to get the size of an array in PHP?
size()
array_size()
sizeof()
None of the above
Which of the following initialization does not represent a multidimensional array in PHP?
$numbers[] = array(1,2,3,4,5); $numbers[] = array(10,20,30,40,50);
$numbers[] = array(1,2,3,5);
$numbers[][] = array(1,2,3,4,5)
None of the above