-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy patharrays.yml
More file actions
186 lines (183 loc) · 8.74 KB
/
arrays.yml
File metadata and controls
186 lines (183 loc) · 8.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
category: Arrays
questions:
-
question: 'Which of the following is not valid syntax for creating a new array key?'
answers:
- {value: '$a[] = "value";', correct: false}
- {value: '$a{} = "value";', correct: true}
- {value: '$a[0] = "value";', correct: false}
- {value: '$a{0} = "value";', correct: false}
- {value: '$a[$b = 0] = "value";', correct: false}
-
question: 'Which of the following functions will sort an array in ascending order by value, while preserving key associations?'
answers:
- {value: 'asort()', correct: true}
- {value: 'usort()', correct: false}
- {value: 'krsort()', correct: false}
- {value: 'ksort()', correct: false}
- {value: 'sort()', correct: false}
-
question: |
What is the output of the following code block?
$a = "The quick brown fox jumped over the lazy dog.";
$b = array_map("strtoupper", explode(" ", $a));
foreach ($b as $value) {
echo "$value ";
}
answers:
- {value: 'THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.', correct: true}
- {value: 'A PHP Error', correct: false}
- {value: 'Array Array Array Array Array Array Array Array Array', correct: false}
-
question: 'Which from the following list is not an appropriate use of an array?'
answers:
- {value: 'As a list', correct: false}
- {value: 'All of these uses are valid', correct: true}
- {value: 'As a Lookup Table', correct: false}
- {value: 'A Stack', correct: false}
- {value: 'As a hash table', correct: false}
-
question: |
What is the output of this code snippet?
$a = [0.001 => 'b', .1 => 'c'];
var_dump($a);
answers:
- {value: 'An empty array', correct: false}
- {value: "0.001 => 'b', .1 => c", correct: false}
- {value: "0 => 'c'", correct: true}
- {value: "'0.001' => 'b', '0.1' => c'", correct: false}
- {value: 'A Syntax Error', correct: false}
-
question: 'Which of the following functions could be used to break a string into an array?'
answers:
- {value: 'array_split()', correct: false}
- {value: 'split()', correct: true}
- {value: 'string_split()', correct: false}
- {value: 'preg_match_all()', correct: true}
- {value: 'explode()', correct: true}
-
question: 'If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?'
answers:
- {value: "$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';", correct: true}
- {value: "range('A', 'Z');", correct: true}
- {value: 'explode("", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");', correct: false}
- {value: 'You would use the ALPHA_ARRAY constant', correct: false}
- {value: 'None of the above', correct: false}
-
question: |
What is the output of the following code block?
$array = [1 => 0, 2, 3, 4];
array_splice($array, 3, count($array), array_merge(['x'], array_slice($array, 3)));
var_dump($array);
answers:
- {value: '1 => 1, 2 => 2, 3 => x, 4 => 4', correct: false}
- {value: '0 => 1, 2 => 2, 3 => 3, 4 => 4, x => 3', correct: false}
- {value: '0 => 0, 1 => 2, 2 => 3, 3 => x, 4 => 4', correct: true}
- {value: '0 => x, 1 => 0, 2 => 1, 3 => 2, 4 => 3', correct: false}
- {value: '1 => 1, 3 => x, 2 => 2, 4 => 4', correct: false}
-
question: 'Which function would you use to add an element to the beginning of an array?'
answers:
- {value: 'array_shift()', correct: false}
- {value: 'array_push()', correct: false}
- {value: '$array[0] = "value";', correct: false}
- {value: 'array_unshift()', correct: true}
- {value: 'array_pop()', correct: false}
-
question: |
Which key will not be displayed from the following code block?
$array = ['a' => 'John',
'b' => 'Coggeshall',
'c' => ['d' => 'John',
'e' => 'Smith']
];
function display($item, $key) {
echo "$key => $item\n";
}
array_walk_recursive($array, "display");
answers:
- {value: 'd', correct: false}
- {value: 'c', correct: true}
- {value: 'b', correct: false}
- {value: 'a', correct: false}
- {value: 'They all will be displayed', correct: false}
-
question: |
What is the result of the following code snippet?
$array = ['a' => 'John',
'b' => 'Coggeshall',
'c' => ['d' => 'John',
'e' => 'Smith']
];
function something($array) {
extract($array);
return $c['e'];
}
echo something($array);
answers:
- {value: 'Smith', correct: true}
- {value: 'A PHP Warning', correct: false}
- {value: 'Coggeshall', correct: false}
- {value: 'NULL', correct: false}
- {value: 'Array', correct: false}
-
question: |
What should go in the missing line ????? below to produce the output shown?
$array_one = [1, 2, 3, 4, 5];
$array_two = ['A', 'B', 'C', 'D', 'E'];
???????
print_r($array_three);
Result:
Array
(
[5] => A
[4] => B
[3] => C
[2] => D
[1] => E
)
answers:
- {value: '$array_three = array_merge(array_reverse($array_one), $array_two);', correct: false}
- {value: '$array_three = array_combine($array_one, $array_two);', correct: false}
- {value: '$array_three = array_combine(array_reverse($array_one), $array_two);', correct: true}
- {value: '$array_three = array_merge($array_one, $array_two);', correct: false}
- {value: '$array_three = array_reverse($array_one) + $array_two;', correct: false}
-
question: 'Which of the following functions are used with the internal array pointer to accomplish an action?'
answers:
- {value: 'key', correct: true}
- {value: 'forward', correct: false}
- {value: 'prev', correct: true}
- {value: 'current', correct: true}
- {value: 'next', correct: true}
-
question: |
Given the following array:
$array = [1, 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 3, 2, 2, 2];
The fastest way to determine the total number a particular value appears in the array is to use which function?
answers:
- {value: 'array_total_values', correct: false}
- {value: 'array_count_values', correct: true}
- {value: 'A foreach loop', correct: false}
- {value: 'count', correct: false}
- {value: 'a for loop', correct: false}
-
question: 'The ____ construct is particularly useful to assign your own variable names to values within an array.'
answers:
- {value: 'array_get_variables', correct: false}
- {value: 'current', correct: false}
- {value: 'each', correct: false}
- {value: 'import_variables', correct: false}
- {value: 'list', correct: true}
-
question: |
The following code snippet displays what for the resultant array?
$a = [1 => 0, 3 => 2, 4 => 6];
$b = [3 => 1, 4 => 3, 6 => 4];
print_r(array_intersect($a, $b));
answers:
- {value: '1 => 0', correct: false}
- {value: '1 => 3, 3 => 1, 4 => 3', correct: false}
- {value: '3 => 1, 3=> 2, 4 => 3, 4=> 6', correct: false}
- {value: '1 => 0, 3 => 2, 4 => 6', correct: false}
- {value: 'An empty Array', correct: true}