PHP Arrays Multiple Choice Questions

1)
Array values are keyed by ______ values (called indexed arrays) or using ______ values (called associative arrays). Of course, these key methods can be combined as well.

A) Float, string
B) Positive number, negative number
C) Even number, string
D) String, Boolean
E) Integer, string

2)
What will the following script output?

<?php
$array = array (1, 2, 3, 5, 8, 13, 21, 34, 55);
$sum = 0;
for ($i = 0; $i < 5; $i++) {
$sum += $array[$array[$i]];
}
echo $sum;
?>

A) 78
B) 19
C) NULL
D) 5
E) 0

3)
What elements will the following script output?

<?php
$array = array (true => 'a', 1 => 'b');
var_dump ($array);
?>

A) 1 => 'b'
B) True => 'a', 1 => 'b'
C) 0 => 'a', 1 => 'b'
D) None
E) It will output NULL

4)
Which array function checks if the specified key exists in the array

A) array_key_exist()
B) array_key_exists()
C) array_keys_exists()
D) arrays_key_exists()

5)
There are three different kind of arrays:

A) Numeric array, String array, Multidimensional array
B) Numeric array, Associative array, Dimensional array
C) Numeric array, Associative array, Multidimensional array
D) Const array, Associative array, Multidimensional array

6)
Absent any actual need for choosing one method over the other, does passing arrays by value to a read-only function reduce performance compared to passing them by reference?

A) Yes, because the interpreter must always create a copy of the array before passing it to the function.
B) Yes, but only if the function modifies the contents of the array.
C) Yes, but only if the array is large.
D) Yes, because PHP must monitor the execution of the function to determine if
changes are made to the array.
E) No.

7)
Assume you would like to sort an array in ascending order by value while preserving key associations. Which of the following PHP sorting functions would you use?

A) ksort()
B) asort()
C) krsort()
D) sort()
E) usort()

8)
What function computes the difference of arrays?

A) array_diff
B) diff_array
C) arrays_diff
D) diff_arrays

9)
What functions count elements in an array?

A) count
B) Sizeof
C) Array_Count
D) Count_array

10)
What array will you get if you convert an object to an array?

A) An array with properties of that object as the array's elements.
B) An array with properties of that array as the object's elements.
C) An array with properties of that object as the Key elements.
D) An array with keys of that object as the array's elements.

Answers