What is the difference between array_map, array_filter, and array_reduce?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
These are PHP's core higher-order array functions. array_map($callback, $array) applies a callback to each element and returns a new array of the same size with the transformed values. array_filter($array, $callback) passes each element through a callback and returns a new array with only elements for which the callback returns true (preserves keys). Without a callback, it removes falsy values. array_reduce($array, $callback, $initial) reduces the array to a single value by passing an accumulator and the current element to the callback — useful for sums, building strings, or creating new data structures from an array. All three are non-destructive — they return new arrays/values without modifying the original.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex PHP answers easy to follow.