Array Functions in PHP
From the PHP cheat sheet · Arrays · verified Jul 2026
Array Functions
Built-in array manipulation functions
php
// Common array functions
$numbers = [3, 1, 4, 1, 5];
// Sorting
sort($numbers); // [1, 1, 3, 4, 5]
rsort($numbers); // Reverse sort
// Array operations
$sum = array_sum($numbers);
$unique = array_unique($numbers);
$filtered = array_filter($numbers, fn($n) => $n > 2);
$mapped = array_map(fn($n) => $n * 2, $numbers);
// Search and check
$key = array_search(4, $numbers);
$exists = in_array(3, $numbers);💡 array_map transforms, array_filter selects, array_reduce aggregates
⚡ Spaceship operator (<=>) simplifies comparisons
📌 array_merge re-indexes, + operator preserves keys
🔥 array_column great for extracting from multi-dimensional arrays