1. Home
  2. Computer Science MCQs
  3. PHP
  4. What does array_map(fn($x) => $x * 2, [1, 2, 3]) return?

Added 2 Nov 2026

What does array_map(fn($x) => $x * 2, [1, 2, 3]) return?

  1. [1, 2, 3, 2]
  2. [2, 2, 2]
  3. 12
  4. [2, 4, 6] Correct answer

Correct answer

D. [2, 4, 6]

16 views

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs