PHP Questions and Answers – Arrays – Part 2
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP Arrays”.
1. In comparison with associative arrays vector are often ________
A Faster
B Slower
C Stable
D None of the above
2. What is the result of the following PHP code?
<?php
$nbr = array ("1", "2", "3", "4");
echo(next($nbr));
?>
A 1
B 2
C 3
D 4
3. What is the result of the following PHP code?
<?php
$arr1 = array("A", "B");
$arr2 = array("C", "D");
$arr3 = array_merge($arr1, $arr2);
print_r($arr3);
?>
A Array([1] => A, [2] => B, [3] => C, [4] => D)
B Array([0] => A, [1] => B, [2] => C, [3] => D)
C Array([2] => C, [1] => B, [0] => A, [3] => D)
D None of the above
4. Which of the following built-in functions return true if the parameter is an array or false if it is not an array?
A in_array()
B is_array()
C this_array()
D do_array()
5. What is the result of the following PHP code?
<?php
$colors = array ("Blue", "Black", "Yellow", "Green");
$colors = array_flip($colors);
echo ($colors[0]);
?>
A Blue
B Green
C 0
D Error
6. What is the result of the following PHP code?
<?php
$languages = array ("PHP", "Java", "C++");
echo (next($languages));
echo (next($languages));
?>
A PHPJava
B PHPC++
C JavaC++
D None of the above
7. Which of the following built-in functions allow us to get the previous element in an array?
A previous()
B prev()
C before()
D last()
8. What is the result of the following PHP code?
<?php
$states = array(
"United states" =>
array(
"population" => "22,12,000",
"captial" => "Washington"
),
"Washington" =>
array(
"population" => "9,80,000",
"captial" => "Washington"
)
);
echo $states["United states"]["population"];
?>
A 22,12,000
B 9,80,000
C United states population
D United states 22,12,000
9. What is the result of the following PHP code?
<?php
$array = array (1, 2, 3, 4, 1);
$sum = 0;
for ($i = 0; $i < 4; $i++) {
$sum += $array[$array[$i]];
}
echo $sum;
?>
A 11
B 10
C 12
D 9
10. What is the result of the following PHP code?
<?php
$array = array (true => 'a', 1 => 'b');
var_dump ($array);
?>
A True => ‘a’, 1 => ‘b’
B 1 => ‘b’
C 0 => ‘a’, 1 => ‘b’
D None


