What does array_map(fn($x) => $x * 2, [1, 2, 3]) return?
-
A
[1, 2, 3, 2]
-
B
[2, 2, 2]
-
C
12
-
D
[2, 4, 6]
Correct answer
Correct answer
D. [2, 4, 6]
16 views
Explanation
array_map() applies the callback to every element and returns a new array. The fn() arrow-function syntax was added in PHP 7.4.
Reference
Asked in: NTS, PHP Developer Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ