count() | Returns the number of elements in an array | count([1, 2, 3]) → 3 |
sizeof() | Alias of count() | sizeof([1, 2, 3]) → 3 |
array_push() | Adds one or more elements to the end of an array | $arr = [1, 2]; array_push($arr, 3, 4); → [1, 2, 3, 4] |
array_pop() | Removes and returns the last element of an array | $arr = [1, 2, 3]; array_pop($arr); → 3 |
array_unshift() | Adds elements to the beginning of an array | $arr = [2, 3]; array_unshift($arr, 1); → [1, 2, 3] |
array_shift() | Removes and returns the first element of an array | $arr = [1, 2, 3]; array_shift($arr); → 1 |
array_merge() | Merges two or more arrays | array_merge([1, 2], [3, 4]) → [1, 2, 3, 4] |
array_combine() | Creates an array using one array as keys and another as values | array_combine(["a", "b"], [1, 2]) → ["a" => 1, "b" => 2] |
array_slice() | Extracts a portion of an array | array_slice([1, 2, 3, 4], 1, 2) → [2, 3] |
array_splice() | Removes elements and replaces them with new ones | $arr = [1, 2, 3, 4]; array_splice($arr, 1, 2, ["X"]); → [1, "X", 4] |
array_keys() | Returns an array of all keys from an array | array_keys(["a" => 1, "b" => 2]) → ["a", "b"] |
array_values() | Returns all values from an array | array_values(["a" => 1, "b" => 2]) → [1, 2] |
array_flip() | Swaps keys with values in an array | array_flip(["a" => 1, "b" => 2]) → [1 => "a", 2 => "b"] |
array_reverse() | Reverses the order of array elements | array_reverse([1, 2, 3]) → [3, 2, 1] |
array_unique() | Removes duplicate values from an array | array_unique([1, 2, 2, 3]) → [1, 2, 3] |
in_array() | Checks if a value exists in an array | in_array(2, [1, 2, 3]) → true |
array_search() | Searches for a value and returns its key | array_search(2, [1, 2, 3]) → 1 |
array_diff() | Returns the difference between arrays (values not in the second array) | array_diff([1, 2, 3], [2, 3]) → [1] |
array_intersect() | Returns common values between arrays | array_intersect([1, 2, 3], [2, 3, 4]) → [2, 3] |
array_map() | Applies a function to each element of an array | array_map('strtoupper', ['a', 'b', 'c']) → ['A', 'B', 'C'] |
array_filter() | Filters an array using a callback function | array_filter([1, 2, 3, 4], fn($x) => $x % 2 == 0) → [2, 4] |
array_reduce() | Reduces an array to a single value using a function | array_reduce([1, 2, 3], fn($carry, $item) => $carry + $item, 0) → 6 |
sort() | Sorts an array in ascending order | $arr = [3, 1, 2]; sort($arr); → [1, 2, 3] |
rsort() | Sorts an array in descending order | $arr = [3, 1, 2]; rsort($arr); → [3, 2, 1] |
asort() | Sorts an associative array by values | $arr = ["b" => 2, "a" => 1]; asort($arr); → ["a" => 1, "b" => 2] |
ksort() | Sorts an associative array by keys | $arr = ["b" => 2, "a" => 1]; ksort($arr); → ["a" => 1, "b" => 2] |
shuffle() | Randomizes the order of elements in an array | shuffle($arr); → (Random output) |