A PHP Array Quiz tests your understanding of array concepts, syntax, and operations in PHP.
Question 1
What type of array uses numeric indexes starting from 0 in PHP?
Associative Array
Indexed Array
Multidimensional Array
Static Array
Question 2
Which type of PHP array uses named keys instead of numeric indexes?
Indexed Array
Static Array
Associative Array
Multidimensional Array
Question 3
What is a multidimensional array in PHP?
An array containing only numeric values
An array containing other arrays as elements
An array that only stores strings
An array with a fixed size
Question 4
Which PHP function adds elements to the end of an indexed array?
array_unshift()
array_push()
array_pop()
unset()
Question 5
How can you remove the last element from an indexed array?
array_shift()
array_pop()
unset()
array_unshift()
Question 6
How do you sort the array $numbers = [3, 1, 4, 1, 5];
in ascending order?
sort($numbers);
rsort($numbers);
asort($numbers);
ksort($numbers);
Question 7
How do you merge two arrays $array1 = [1, 2, 3];
and $array2 = [4, 5, 6];
?
$merged = $array1 + $array2;
$merged = array_merge($array1, $array2);
$merged = array_combine($array1, $array2);
$merged = array_intersect($array1, $array2);
Question 8
How to count the number of elements in the array $numbers
?
length($numbers);
sizeof($numbers);
count($numbers);
total($numbers);
Question 9
What is the difference between array_shift()
and array_pop()
?
array_shift()
adds an element to start, array_pop()
removes from the end
array_shift()
removes first element, array_pop()
removes last element
array_shift()
removes the the
last element, array_pop()
removes the first element
Both remove the last element
Question 10
How do you access the "name" element in the associative array $person = ["name" => "GFG", "age" => 30];
?
echo $person[1];
echo $person["name"];
echo $person["GFG"];
echo $person["age"];
There are 10 questions to complete.