array_map, array_filter, array_reduce — The Functional Trio
PHP's array functions have always been powerful, but with arrow functions (7.4) and first-class callables (8.1), they've become genuinely elegant. Transform, filter, and reduce collections without a single foreach loop.
$orders = getOrders();
// Transform: extract what you need
$totals = array_map(fn($o) => $o->total, $orders);
// Filter: keep what matches
$large = array_filter($orders, fn($o) => $o->total > 100);
// Reduce: collapse to a single value
$sum = array_reduce($orders, fn($carry, $o) => $carry + $o->total, 0);
// Compose them for expressive pipelines
$report = array_reduce(
array_map(
fn($o) => ['month' => $o->date->format('Y-m'), 'total' => $o->total],
array_filter($orders, fn($o) => $o->status === Status::Completed),
),
function ($acc, $item) {
$acc[$item['month']] = ($acc[$item['month']] ?? 0) + $item['total'];
return $acc;
},
[],
);
// Plus the underrated helpers:
$keys = array_keys($map);
$values = array_values($filtered); // Re-index after filter
$combined = array_combine($keys, $values);
$unique = array_unique($tags);
$chunks = array_chunk($items, 50); // Batch processing
PHP arrays are ordered hash maps — they work as lists, dictionaries, sets, stacks, and queues. The standard library gives you phparray_map, phparray_filter, phparray_reduce, and 75+ other array functions out of the box.
Significance: Versatility
PHP's array is the Swiss Army knife of data structures. Its combination of ordered keys, mixed types, and a massive standard library of manipulation functions means you rarely need external collection libraries. With arrow functions, the functional style is now as concise as any language.