Open In App
Related Articles

PHP Array Functions Complete Reference

Improve Article
Save Article
Like Article

PHP Arrays are a type of data structure that allows to storing of multiple elements of a similar type under a single variable by saving the effort of creating a different variable for every data. The arrays are helpful to create a list of elements of similar types, which can be accessed using their index or key. The array functions are allowed to interact and manipulate the array elements in various ways. The PHP array inbuilt functions are used for simple and multi-dimensional arrays.

Installation: These functions have not required any installation. These are part of PHP core.

Below programs illustrate the array_diff_uassoc() function in PHP: 


// PHP program to illustrate the
// array_diff_uassoc() function
// user defined function that returns 0 if
// $array1's keys are equal to any other
// input array, else returns 1 if greater,
// or -1 if smaller
function user_function($a, $b)
if ($a===$b)
    return 0;
return ($a>$b)? 1: -1;
// Input Arrays
$a1=array(10=>"striver", 20=>"raj", 30=>"geek");
$a2=array(20=>"striver", 10=>"raj", 30=>"geek");
$result = array_diff_uassoc($a1, $a2, "user_function");


    [10] => striver
    [20] => raj

The complete list of Array Functions are given below:

PHP Array Functions



array_chunk()Split an array into parts or chunks of a given size.
array_combine()Create a new array by using one array for keys and another array for values.
 array_count_values() Count all the values inside an array.
array_diff_assoc()Get the difference between one or more arrays.
array_diff_keys()Get the difference between one or more arrays. 
array_diff_uassoc()Compare the keys and values of the user-defined function.
array_diff_ukey()Compares the key to two or more arrays 
array_diff() Calculate the difference between two or more arrays. 
 array_fill_keys()Create a new array filled with the given keys and value provided as an array to the function.
array_fill()Fill an array with values.
array_filter() Filter the elements of an array using a user-defined function.
array_flip()Exchange elements within an array
array_intersect_assoc()Compute the intersection of two or more arrays.
array_intersect_key()Compute the intersection of two or more arrays.
array_intersect_uassoc()Compare key and values of two or more arrays 
array_intersect()Compare the values of two or more arrays and returns the matches.
array_key_exists()Check whether a specific key or index is present inside an array or not.
array_keys()Return either all the keys of an array or the subset of the keys.
array_merge_recursive()Merge two or more arrays into a single array recursively. 
array_multisort()Sort multiple arrays at once or a multi-dimensional array with each individual dimension.
array_pad()Pad a value fixed number of time onto an array.
array_pop()Delete or pop out and return the last element from an array passed to it as a parameter.
array_product()The products of all the elements in an array.
array_push()Push new elements into an array.
array_rand() Fetch a random number of elements from an array.
array_reduce() Reduce the elements of an array into a single value
array_replace_recursive()Replaces the values of the first array with the values
array_replace()It takes a list of arrays separated by commas (,) as parameters 
array_reverse()Reverse the elements of an array including the nested arrays.
array_search() Search for a particular value in an array
array_shift()Shifts an element off from the beginning in an array.
array_slice()Fetch a part of an array by slicing through it, according to the users choice.
array_splice()Replaces the existing element with elements from other arrays and returns an array 
array_sum()It takes an array parameter and returns the sum of all the values in it.
array_udiff_assoc()The function computes the difference arrays from two or more arrays
array_udiff()Distinguishing between two or more arrays.
array_uintersect_assoc()Compute the intersection of the array of keys for different values of two or more arrays.
array_uintersect_uassoc() Computes the intersection of two arrays.
array_uintersect() Compute the intersection of two or more arrays depending on the values
array_unique() This function removes duplicate
array_unshift() Elements are added to the beginning of the array. 
array_values() Get an array of values from another array that may contain key-value pairs or just values.
array_walk_recursive()The array element’s keys and values are parameters in the callback function.
array_walk() It is a user-defined function to every element of the array.
array() This is used to create an array. 
arsort() Sort an array according to values.
compact()Create an array using variables. 
count() Count the current elements in the array. 
current() Return the value of the element in an array which is the internal pointer.
end()Find the last element of the given array.
extract() The extract() function does array to variable conversion. 
in_array()Check whether a given value exists in an array or not.
key() Return the index of the element of a given array to which is the internal pointer.  
krsort() Sort an array by key in reverse order according to its index values.
ksort() Sort an array in ascending order according to its key values.
list()Assign array values to multiple variables at a time.
natcasesort()Sort an array by using a “natural order” algorithm.
natsort()Sort an array by using a “natural order”, it does not check the type of value for comparison
next()The next() function increments the internal pointer after returning the value
pos()Return the value of the element in an array to which the internal pointer is currently pointing.
prev()Return the immediate previous element from an array
range()Create an array of elements of any kind such as integers, alphabets within a given range
reset()Move any array’s internal pointer to the first element of that array.
rsort()Sort the array in descending order i.e, greatest to smallest.
shuffle()Shuffle or randomize the order of the elements in an array.
sizeof()Count the number of elements present in an array or any other countable object.
sort()Sort an array in ascending order i.e, smaller to greater.
uasort()Sort an array such that array indices maintain their correlation with the array elements 
uksort()Sort an array according to the keys and not values using a user-defined comparison function.
usort()Sort arrays in an easier way. Here, we are going to discuss a new function usort(). 
each()Get the current element key-value pair of the given array to which the internal pointer is currently pointing


Last Updated : 20 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials