1. Overview of PHP Array Functions
PHP provides a comprehensive suite of built-in array manipulation functions that streamline data handling without manual nested loops.
2. Array Size and Key Checking
count($array): Returns total element count.in_array($value, $array): Checks if a value exists within an array.array_key_exists($key, $array): Checks if a specified key exists in an associative array.
";
}
3. Merging and Slicing Arrays
4. Functional Transformations: array_map, array_filter, array_reduce
$n % 2 === 0);
// array_map: double every element
$doubled = array_map(fn($n) => $n * 2, $numbers);
// array_reduce: sum all elements into a single aggregate
$totalSum = array_reduce($numbers, fn($carry, $item) => $carry + $item, 0);
5. Sorting Arrays
| Function | Key / Value Preserved | Order |
|---|---|---|
sort() |
Values (re-indexes keys) | Ascending |
rsort() |
Values (re-indexes keys) | Descending |
asort() |
Maintains key-value associations | Ascending by Value |
ksort() |
Maintains key-value associations | Ascending by Key |