PHP Questions and Answers – Arrays – Part 3
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP Arrays”.
1. Which of the following built-in functions is used to check if the specified key exists in the array?
A arrays_key_exists()
B array_keys_exists()
C array_key_exists()
D array_key_exist()
2. If we transfer arrays by value to a read-only function is it decreasing the performance of execution in comparison with transferring them by reference?
A Yes, since the interpreter needs constantly to create a copy of the array before transfer it to the function.
B Yes, but only if the function changes the array values.
C Yes, but only if the array is big.
D Yes, since PHP should monitor the execution of the function to determine if changes are made to the array.
E No.
3. Which of the following built-in functions is used to compute the difference of arrays?
A arrays_dif()
B diff_array()
C array_diff()
D dif_arrays()
4. Suppose you want to sort an array in ascending order by value while keeping key associations. Which of the following built-in functions would you use?
A sort()
B usort()
C krsort()
D asort()
E ksort()
5. Which of the following built-in functions is used to count elements in an array?
A Count_array
B Array_Count
C Sizeof
D count
6. What is the result of the following PHP code?
<?php $arr1 = array("A"=>"Alex", "B"=>"Bob", "E"=>"Emily"); $arr2 = array("L"=>"Alex", "O"=>"Bob"); $result = array_intersect($arr1, $arr2); print_r($result); ?>
A Array([A] => Alex, [B] => Bob)
B Array([L] => Alex, [O] => Bob)
C Array([E] => Emily)
D Array()
7. What is the result of the following PHP code?
<?php $arr = array(2, 1, 3); echo(array_product($arr)); ?>
A 3
B 2
C 6
D 1
8. What is the result of the following PHP code?
<?php $arr1 = array("A", "B"); $arr2 = array("C", "D"); $arr3 = array_replace($arr1, $arr2); print_r($arr3); ?>
A Array([0] => C, [1] => D)
B Array([0] => A, [1] => B)
C Array([0] => A, [1] => D)
D Array([0] => C, [1] => B)
9. What is the result of the following PHP code?
<?php $arr = array("A", "B", "C", "D"); echo pos($arr); ?>
A D
B A
C 0
D True
10. What is the result of the following PHP code?
<?php $nbr = range(0, 2); print_r ($nbr); ?>
A Array([0] => 0, [1] => 1, [2] => 2)
B Array([1] => 1, [2] => 2)
C Array([0] => 0, [1] => 1)
D None of the above