Reference to PHP Array Functions
In the PHP programming language, arrays act as versatile containers that can hold multiple values under a single name. There is no fixed size limit, allowing you to store as many values as needed. This guide provides a complete reference to all PHP array functions, helping you understand and apply them to create, modify, and manage arrays effectively.
Alphabetical Reference
The table below lists all 87 PHP array functions, arranged in alphabetical order.
Function | Description |
---|---|
array() | Creates a new array in PHP to store multiple values under one variable. |
array_all() | Checks whether all elements in an array satisfy a given callback condition. |
array_any() | Checks whether at least one element in an array satisfies a given callback condition. |
array_change_key_case() | Changes all array keys to uppercase or lowercase for consistent formatting. |
array_chunk() | Splits an array into smaller arrays, each containing a set number of elements. |
array_column() | Extracts values from a specific column in a multi-dimensional PHP array. |
array_combine() | Creates an array by combining one array of keys with another of values. |
array_count_values() | Counts all unique values in an array and returns the total for each. |
array_diff() | Compares two arrays and returns values present in the first but not the second. |
array_diff_assoc() | Compares keys and values of arrays, returning differences with key association. |
array_diff_key() | Compares only the keys of two arrays and returns unmatched keys. |
array_diff_uassoc() | Compares arrays using keys, values, and a user-defined function to find differences. |
array_diff_ukey() | Compares keys of two arrays using a user-defined function to find differences. |
array_fill() | Fills an array with a specified value, starting from a given index. |
array_fill_keys() | Fills an array with values, assigning them to a specified list of keys. |
array_filter() | Filters an array’s values using a callback function to determine matches. |
array_find() | Finds and returns the first element in an array that satisfies a given callback condition. |
array_find_key() | Finds and returns the first key in an array whose value satisfies a given callback condition. |
array_flip() | Swaps the keys and values of an array for reversed mapping. |
array_intersect() | Returns values that are common between two or more arrays. |
array_intersect_assoc() | Compares two arrays’ keys and values, returning matching pairs only. |
array_intersect_key() | Compares the keys of two arrays and returns the keys that match. |
array_intersect_uassoc() | Finds matches in arrays using keys, values, and a user-defined comparison function. |
array_intersect_ukey() | Compares array keys using a user-defined function and returns matching keys. |
array_is_list() | Checks if an array is a list with sequential numeric keys starting from zero. |
array_key_exists() | Checks whether a specified key exists in an array. |
array_key_first() | Returns the first key of an array without changing its internal pointer. |
array_key_last() | Returns the last key of an array without affecting its pointer. |
array_keys() | Returns all keys from an array as a numeric array. |
array_map() | Applies a user-defined function to each value of one or more arrays. |
array_merge() | Merges one or more arrays into a single array. |
array_merge_recursive() | Merges arrays recursively, combining values with the same keys into sub-arrays. |
array_multisort() | Sorts multiple or multi-dimensional arrays in parallel. |
array_pad() | Pads an array to a specified length with a given value. |
array_pop() | Removes and returns the last element of an array. |
array_product() | Calculates and returns the product of all values in an array. |
array_push() | Adds one or more elements to the end of an array. |
array_rand() | Returns one or more random keys from an array. |
array_reduce() | Reduces an array to a single value using a callback function. |
array_replace() | Replaces values in the first array with values from subsequent arrays. |
array_replace_recursive() | Recursively replaces values in the first array with values from others. |
array_reverse() | Reverses the order of elements in an array. |
array_search() | Searches for a value in an array and returns the matching key. |
array_shift() | Removes and returns the first element of an array. |
array_slice() | Extracts and returns a portion of an array based on offset and length. |
array_splice() | Removes and optionally replaces selected elements within an array. |
array_sum() | Calculates and returns the sum of all values in an array. |
array_udiff() | Returns differences between arrays using a user-defined function to compare values. |
array_udiff_assoc() | Compares keys with built-in function and values with user-defined function to find differences. |
array_udiff_uassoc() | Finds array differences by comparing keys and values with two user-defined functions. |
array_uintersect() | Finds matches between arrays using a user-defined function to compare values. |
array_uintersect_assoc() | Matches arrays by comparing keys with built-in function and values with user-defined function. |
array_uintersect_uassoc() | Matches arrays by comparing keys and values using two user-defined functions. |
array_unique() | Removes duplicate values from an array, returning only unique entries. |
array_unshift() | Adds one or more elements to the beginning of an array. |
array_values() | Returns all values from an array, reindexing them numerically. |
array_walk() | Applies a user-defined function to each element of an array. |
array_walk_recursive() | Recursively applies a user-defined function to each element of an array. |
arsort() | Sorts an associative array in descending order by its values. |
asort() | Sorts an associative array in ascending order by its values. |
compact() | Creates an array from given variables and their values. |
count() | Returns the total number of elements in an array. |
current() | Returns the current element from a PHP array without changing its pointer. |
each() | Returns the current key and value from an array, then moves the pointer forward. Deprecated. |
end() | Moves the internal array pointer to the last element and returns it. |
extract() | Imports array keys as variables, assigning them their corresponding values. |
in_array() | Checks if a specific value exists in a PHP array. |
iterator_to_array() | Converts the elements of an iterator into an array, with an option to preserve keys. |
key() | Returns the key of the current array element. |
key_exists() | Checks if a specific key exists in an array (alias of array_key_exists()). |
krsort() | Sorts an associative array by keys in descending order. |
ksort() | Sorts an associative array by keys in ascending order. |
list() | Assigns array values to a list of variables in one step. |
natcasesort() | Sorts an array using a case-insensitive "natural order" algorithm. |
natsort() | Sorts an array using a case-sensitive "natural order" algorithm. |
next() | Moves the array pointer to the next element and returns it. |
pos() | Returns the current element of an array (alias of current()). |
prev() | Moves the array pointer to the previous element and returns it. |
range() | Creates an array containing elements in a specified range. |
reset() | Resets the array pointer to the first element and returns it. |
rsort() | Sorts an indexed array in descending order by values. |
shuffle() | Randomizes the order of elements in an array. |
sizeof() | Returns the number of elements in an array (alias of count()). |
sort() | Sorts an indexed array in ascending order by values. |
uasort() | Sorts an array by values using a user-defined comparison function. |
uksort() | Sorts an array by keys using a user-defined comparison function. |
usort() | Sorts an array by values using a user-defined comparison function. |