PHP 7 Array Functions
The following section contains a list of PHP array functions along with a brief description.
PHP Array Functions
Here is a complete list of array functions belonging to the latest PHP 7. These functions are the part of the PHP core so you can use them within your script without any further installation.
Also, deprecated function such as each()
is not included in the list.
Function | Description |
---|---|
array_change_key_case() |
Changes the case of all keys in an array to lowercase or uppercase. |
array_chunk() |
Splits an array into chunks of arrays. |
array_column() |
Returns the values from a single column in the input array. |
array_combine() |
Creates an array by using one array for keys and another for its values. |
array_count_values() |
Counts all the distinct values of an array. |
array_diff() |
Compare arrays values, and returns the differences. |
array_diff_assoc() |
Compare arrays values, with additional key check, and returns the differences. |
array_diff_key() |
Compare arrays keys, and returns the differences. |
array_diff_uassoc() |
Compare arrays values, with additional key check using a user-defined key comparison function, and returns the differences. |
array_diff_ukey() |
Compare array keys, using a user-defined key comparison function, and returns the differences. |
array_fill() |
Fills an array with values. |
array_fill_keys() |
Fills an array with values, specifying keys. |
array_filter() |
Filters elements of an array using a user-defined function. |
array_flip() |
Flips or exchanges all keys with their associated values in an array. |
array_intersect() |
Compare arrays values, and returns the matches. |
array_intersect_assoc() |
Compare arrays values, with additional key check, and returns the matches. |
array_intersect_key() |
Compare arrays keys, and returns the matches. |
array_intersect_uassoc() |
Compare arrays values, with additional key check using a user-defined key comparison function, and returns the matches. |
array_intersect_ukey() |
Compare arrays keys, using a user-defined key comparison function, and returns the matches. |
array_key_exists() |
Checks if the specified key exists in the array. |
array_key_first() |
Gets the first key of an array. |
array_key_last() |
Gets the last key of an array. |
array_keys() |
Returns all the keys or a subsets of the keys of an array. |
array_map() |
Sends the elements of the given arrays to a user-defined function, which may use it to returns new values. |
array_merge() |
Merges one or more arrays into one array. |
array_merge_recursive() |
Merges one or more arrays into one array recursively. |
array_multisort() |
Sorts multiple or multi-dimensional arrays. |
array_pad() |
Inserts a specified number of items, with a specified value, to an array. |
array_pop() |
Removes the last element of an array, and returns the value of the removed element. |
array_product() |
Calculates the product of the values in an array. |
array_push() |
Inserts one or more elements to the end of an array. |
array_rand() |
Returns one or more random keys from an array. |
array_reduce() |
Reduce the array to a single value by using a user-defined callback function. |
array_replace() |
Replaces the values of the first array with the values from following arrays. |
array_replace_recursive() |
Replaces the values of the first array with the values from following arrays recursively. |
array_reverse() |
Returns an array with elements in reverse order. |
array_search() |
Searches an array for a given value and returns the corresponding key if successful. |
array_shift() |
Removes the first element from an array, and returns the value of the removed element. |
array_slice() |
Extract a slice from an array. |
array_splice() |
Removes a portion of the array and replace it with something else. |
array_sum() |
Calculates the sum of values in an array. |
array_udiff() |
Compares arrays values using a user-defined comparison callback function, and returns the differences. |
array_udiff_assoc() |
Compares arrays values using a user-defined comparison callback function, with additional key check, and returns the differences. |
array_udiff_uassoc() |
Compares the keys and values of arrays using two separate user-defined key and value comparison callback functions, and returns the differences. |
array_uintersect() |
Compares arrays values using a user-defined comparison callback function, and returns the matches. |
array_uintersect_assoc() |
Compares arrays values using a user-defined comparison callback function, with additional key check, and returns the matches. |
array_uintersect_uassoc() |
Compares the keys and values of arrays using two separate user-defined key and value comparison callback functions, and returns the matches. |
array_unique() |
Removes duplicate values from an array. |
array_unshift() |
Adds one or more elements to the beginning of an array. |
array_values() |
Returns all the values of an array. |
array_walk() |
Applies a user-defined function to each element of an array. |
array_walk_recursive() |
Applies a user-defined function recursively to each element of an array. |
array() |
Creates an array. |
arsort() |
Sorts an associative array by value, in reverse or descending order. |
asort() |
Sorts an associative array by value, in ascending order. |
compact() |
Creates array containing variables and their values. |
count() |
Returns the number of elements in an array. |
current() |
Returns the current element in an array. |
end() |
Sets the internal pointer of an array to its last element. |
extract() |
Import variables into the current symbol table from an array. |
in_array() |
Checks if a value exists in an array. |
key() |
Fetches a key from an array. |
krsort() |
Sorts an associative array by key, in reverse or descending order. |
ksort() |
Sorts an associative array by key, in ascending order. |
list() |
Assign variables as if they were an array. |
natcasesort() |
Sorts an array using a case insensitive "natural order" algorithm. |
natsort() |
Sorts an array using a "natural order" algorithm. |
next() |
Advance the internal array pointer of an array. |
pos() |
Returns the current element in an array. Alias of current() function. |
prev() |
Rewind the internal array pointer. |
range() |
Creates an array containing a range of elements. |
reset() |
Sets the internal pointer of an array to its first element. |
rsort() |
Sorts an array in reverse or descending order. |
shuffle() |
Shuffles or randomizes the order of the elements in an array. |
sizeof() |
Returns the number of elements in an array. Alias of count() function. |
sort() |
Sorts an array in ascending order. |
uasort() |
Sorts an array using a user-defined comparison function and maintain index association. |
uksort() |
Sorts an array by keys using a user-defined comparison function. |
usort() |
Sorts an array by values using a user-defined comparison function. |