PHP array Quiz Practice Set
Que: (1). What function is used to create an array in PHP?
A.
B.
C.
D.
Que: (2). How do you access the third element of an indexed array named $numbers in PHP?
A.
B.
C.
D.
Que: (3). What function is used to add an element to the end of an array in PHP?
A.
B.
C.
D.
Que: (4). How do you check if a key exists in an associative array in PHP?
A.
B.
C.
D.
Que: (5). What is the correct way to remove an element from an indexed array in PHP?
A.
B.
C.
D.
Que: (6). Which of the following loops is commonly used to iterate over array elements in PHP?
A.
B.
C.
D.
Que: (7). What is the output of the following code snippet?
$array = [1, 2, 3];
echo count($array);
A.
B.
C.
D.
Que: (8). Which of the following functions is used to merge two or more arrays in PHP?
A.
B.
C.
D.
Que: (9). What is the correct way to sort an array in ascending order in PHP?
A.
B.
C.
D.
Que: (10). Which of the following functions is used to extract a slice of an array in PHP?
A.
B.
C.
D.
Que: (11). What is the output of the following PHP code snippet?
$array = [1, 2, 3, 4, 5];
$removed = array_pop($array);
echo $removed;
A.
B.
C.
D.
Que: (12). What function is used to check if a value exists in an array in PHP?
A.
B.
C.
D.
Que: (13). What will be the output of the following PHP code snippet?
$array = [10, 20, 30, 40, 50];
echo array_sum($array);
A.
B.
C.
D.
Que: (14). What function is used to merge the keys of two arrays in PHP?
A.
B.
C.
D.
Que: (15). What is the correct way to check if an array is empty in PHP?
A.
B.
C.
D.
Que: (16). What is the output of the following code?
$array = [0 => "apple", 1 => "banana", 2 => "orange"];
echo array_search("banana", $array);
A.
B.
C.
D.
Que: (17). Which function removes the first element from an array and returns it?
A.
B.
C.
D.
Que: (18). What does the function array_flip() do?
A.
B.
C.
D.
Que: (19). What will the following code output?
$array = ["a" => 1, "b" => 2, "c" => 3];
$result = array_reverse($array);
print_r($result);
A.
B.
C.
D.
Que: (20). Which function can you use to find the difference between two arrays?
A.
B.
C.
D.
Que: (21). What is the output of the following code?
$array = ["apple", "banana", "orange"];
echo implode("-", $array);
A.
B.
C.
D.
Que: (22). What will count([]) return?
A.
B.
C.
D.
Que: (23). Which function can sort an array in descending order, maintaining key-value associations?
A.
B.
C.
D.
Que: (24). What is the output of the following code?
$array = ["x" => 10, "y" => 20, "z" => 30];
echo $array["y"];
A.
B.
C.
D.
Que: (25). Which function shuffles the elements of an array?
A.
B.
C.
D.
Que: (26). What does the array_unique() function do?
A.
B.
C.
D.
Que: (27). Which function is used to split an array into chunks?
A.
B.
C.
D.
Que: (28). What is the output of the following code?
$array = ["a" => 1, "b" => 2];
$array += ["c" => 3];
print_r($array);
A.
B.
C.
D.
Que: (29). What does array_walk() do?
A.
B.
C.
D.
Que: (30). What will the following code output?
$array1 = ['a', 'b', 'c'];
$array2 = ['x', 'y', 'z'];
$result = array_merge($array1, $array2);
print_r($result);
A.
B.
C.
D.
Que: (31). What will be the output of the following code?
$array = ['a', 'b', 'c', 'd'];
array_splice($array, 2, 1, ['x', 'y']);
print_r($array);
A.
B.
C.
D.