Key concepts
- Pure function — given the same arguments, always returns the same result; does not modify external state
- Immutability — data is not mutated; new data is returned
- Higher-order functions — functions that take or return other functions (
map, filter, reduce) - Composition — combining simple functions into more complex ones
Practical use in PHP
$prices = [100, 200, 300];
$discounted = array_map(fn($p) => $p * 0.9, $prices);
$total = array_reduce($discounted, fn($sum, $p) => $sum + $p, 0);
FP vs OOP
These are not competing approaches: modern PHP and JavaScript support both. FP is especially useful for data processing, transformations, and pipelines.