You will find all the useful array functions in PHP. Both, single and multi-dimensional arrays are supported.

No installation or third-party package is required to use these array functions.

Function NameDescription
array()Creates a new array
array_change_key_case()To convert all keys of the array to uppercase or lowercase.
array_chunk()Splits an array into chunks of arrays
array_column()Get the values from a single column in the array
array_combine()Create an array using keys from one array and values from another array
array_count_values()Get the count of elements/values of the array
array_diff() Compare arrays, and returns the differences based on values only
array_diff_assoc() Compare arrays, and returns the differences based on both keys and values
array_diff_key() Compare arrays, and returns the differences based on keys only
array_diff_uassoc() Compare arrays, and returns the differences using a user-defined key comparison function. It compares both keys and values
array_diff_ukey()Compare arrays, and returns the differences using a user-defined key comparison function. It compares keys only
array_fill()Fills the array with values
array_fill_keys()Assign values to the specified keys in the array
array_filter()Filters array values using a callback function
array_flip()Exchange the keys with the corresponding values of an associative array
array_intersect() Compare arrays and return the same values by comparing the values only
array_intersect_assoc() Compare arrays and return the same values by comparing the keys and values
array_intersect_key()Compare arrays and return the same values by comparing the keys only
array_intersect_uassoc() Compare two or more arrays for the same values using a user-defined key comparison function (compare both keys and values)
array_intersect_ukey()Compare two or more arrays for the same values using a user-defined key comparison function (compare only keys)
array_key_exists()Checks specific keys in the array
array_keys()Get all keys of the array
array_map()Pass each value of the array from the user-defined function and return new/modified value
array_merge()Merges one or multiple arrays into one array
array_merge_recursive()Merge one or multiple arrays into one array recursively
array_multisort()Sort one or multidimensional array
array_pad()Inserts a specified number of items, with a specified value, to an array
array_pop()Remove the last element of the array
array_product()Get the product of array values
array_push()Insert element at the last index of the array/end of the array
array_rand()Get random keys from the array
array_reduce()Convert the array into string using user-defined function
array_replace() Replaces the values of the array by values from the arrays
array_replace_recursive()Replaces the values of the array by values from the arrays recursively
array_reverse()Get reverse of the array
array_search()Search specified element of the array and return the key in case of associative array
array_shift()Removes the first element from the array and return it
array_slice()Get a selected portion of the array
array_splice()Removes and replaces specific elements of the array
array_sum()Calculate and return the sum of all values of the array
array_udiff() Compare the arrays and return different values. The values are compared using a user-defined function
array_udiff_assoc() Compare the arrays and return different values. The keys are compared using a built-in function and values are compared using a user-defined function.
array_udiff_uassoc()Compare the arrays and return different values. The key values are compared using a user-defined function
array_uintersect() Compare the arrays and return matching values. Only Values are compared using a user-defined function.
array_uintersect_assoc()Compare the arrays and return matching values. The keys are compared using a built-in function and values are compared using a user-defined function.
array_uintersect_uassoc()Compare arrays, and returns the matches (compare keys and values, using two user-defined key comparison functions)
array_unique()Removes duplicate the array
array_unshift()Adds one or multiple elements to the starting of an array
array_values()Get all the values of the array
array_walk()Apply user function to every element of the array
array_walk_recursive()Get each key value of the array and apply the user-defined function to it
arsort()Sorts an associative array by value in descending order
asort()Sorts an associative array by value in ascending order
compact()Create an array containing variables and their values
count()Returns the number of elements in the array
current()Returns the current element pointed by the pointer of the array
each()Returns the current key-value pair of the array
end()Move the pointer to point the last element of the array
extract()Imports variables into the current symbol table from an array
in_array()Check if the specific element exist in the array or not
key()Get a key from an array
krsort()Sorts an associative array based on key in descending order
ksort()Sorts an associative array based on key in ascending order
list()Assigns variables as if they were an array
natcasesort() Sort array elements according to natural order algorithm (case sensitive)
natsort()Sort array elements according to natural order algorithm
next()Move the array pointer to point to the next element if exist
pos()Alias of the array function current(). Return the index of the position at which the array pointer is
prev()Move the pointer of the array to point to the previous element if exist
range()Creates an array that contains the elements in a defined range
reset()Set the pointer of the array to point to the first element
rsort() Sorts indexed array in descending order
shuffle()Shuffle/randomize the elements of the array
sizeof()This function is an alias of count() function
sort()Sorts indexed array in ascending order
uasort()Sort the array by value according to the function defined by the user
uksort()Sort the array by keys according to the function defined by the user
usort()Sort the array according to the function defined by the user
PHP Array Functions – Array references