PHP Questions and Answers – Arrays – Part 1
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP Arrays”.
1. How many types of array are accessible in PHP?
A 1
B 2
C 3
D 4
2. The array index starts from ______?
A -1
B 0
C 1
D 2
3. Which the following declarations are correct to create an array in PHP?
A name[0] = "Alex";
B $name[] = array("Alex");
C $name[0] = "Alex";
D $name = array("Alex");
4. ______ is an array with more than two dimensions.
A Multi dimensional array
B Single dimensional array
C Both A and B
D None of the above
5. Which of the following built-in functions is used to sort an array in descending order?
A sort()
B asort()
C rsort()
D dsort()
6. Which of the following built-in functions is used to add a value to the end of an array?
A add_array()
B array_unshift()
C inend_array()
D array_push()
7. Which of the following built-in functions returns an array consisting of associative key/value pairs?
A count_values()
B array_count_values()
C array_count()
D count()
8. What is the result of the following PHP code?
<?php $colors = array("Blue", "Orange", "Black"); echo "I like " . $colors[2] . ", " . $colors[1] . " and " . $colors[0] . "."; ?>
A I like Black, Orange and Blue.
B I like Blue, Orange and Black.
C I like Orange, Blue and Black.
D None of the above
9. What is the result of the following PHP code?
<?php $a = array("A","B","C","D","A"); $b = array("A","E","F","D","A"); $c = array_combine($a, $b); print_r($c); ?>
A Array([A] => A, [B] => E, [C] => F, [D] => D, [A] => A)
B Array([A] => A, [B] => E, [C] => F, [D] => D)
C Array([B] => E, [C] => F)
D None of the above
10. What is the result of the following PHP code?
<?php $arr = array ("stack", "how", "to", ".Com"); echo(array_search(".com", $arr) ); ?>
A No Output
B 0
C 3
D Error