PHP Array Functions

PHP provides various array functions to access and manipulate the elements of array. The important PHP array functions are given below.

 

Function Description
array() Creates an array
array_change_key_case() Changes 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 the elements from one “keys” array and one “values” array
array_count_values() Counts all the values of an array
array_key_exists() Checks if the specified key exists in the array
array_keys() Returns all the keys of an array
array_push() Inserts one or more elements to the end of an array
array_filter() Filters the values of an array using a callback function
array_flip() Flips/Exchanges all keys with their associated values in an array
array_pop() Deletes the last element of an array
array_map() Sends each value of an array to a user-made function, which returns new values
array_merge() Merges one or more arrays into one array
array_rand() Returns one or more random keys from an array
array_replace() Replaces the values of the first array with the values from following arrays
count() Returns the number of elements in an array
array_reverse() Returns an array in the reverse order
array_search() Searches an array for a given value and returns the key
array_shift() Removes the first element from an array, and returns the value of the removed element
array_slice() Returns selected parts of an array
array_splice() Removes and replaces specified elements of an array
array_sum() Returns the sum of the values in an array
current() Returns the current element in an array
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 function to every member of an array
array_walk_recursive() Applies a user function recursively to every member of an array
arsort() Sorts an associative array in descending order, according to the value
asort() Sorts an associative array in ascending order, according to the value
rsort() Sorts an indexed array in descending order
extract() Imports variables into the current symbol table from an array
in_array() Checks if a specified value exists in an array
key() Fetches a key from an array
krsort() Sorts an associative array in descending order, according to the key
ksort() Sorts an associative array in ascending order, according to the key
shuffle() Shuffles an array
sizeof() Alias of count()
sort() Sorts an indexed array in ascending order

Leave a Comment