PHP 5 Array Functions
PHP Array Introduction
PHP Array functions allow you to access and manipulate arrays.
Both simple and multi-dimensional arrays are supported.
Installation
PHP Array functions are part of the PHP core. These functions can be used without installation.
PHP 5 Array Functions
| function | Description |
|---|---|
| array() | Creates an array. |
| array_change_key_case() | Returns an array whose keys are all uppercase or lowercase. |
| array_chunk() | Splits an array into new array chunks. |
| array_column() | Returns the values of a single column from the input array. |
| array_combine() | Creates a new array by combining two arrays (one of keys, one of values). |
| array_count_values() | Used to count the occurrences of all values in an array. |
| array_diff() | Compares arrays and returns the difference of the two arrays (comparing values only). |
| array_diff_assoc() | Compares arrays and returns the difference of the two arrays (comparing both keys and values). |
| array_diff_key() | Compares arrays and returns the difference of the two arrays (comparing keys only). |
| array_diff_uassoc() | Compares arrays and returns the difference of the two arrays (comparing keys and values, using a user-defined key comparison function). |
| array_diff_ukey() | Compares arrays and returns the difference of the two arrays (comparing keys only, using a user-defined key comparison function). |
| array_fill() | Fills an array with a given value. |
| array_fill_keys() | Fills an array with a given value at the specified keys. |
| array_filter() | Filters elements of an array using a callback function. |
| array_flip() | Flips/exchanges the keys and their associated values in an array. |
| array_intersect() | Compares arrays and returns the intersection of the two arrays (comparing values only). |
| array_intersect_assoc() | Compares arrays and returns the intersection of the two arrays (comparing both keys and values). |
| array_intersect_key() | Compares arrays and returns the intersection of the two arrays (comparing keys only). |
| array_intersect_uassoc() | Compares arrays and returns the intersection of the two arrays (comparing keys and values, using a user-defined key comparison function). |
| array_intersect_ukey() | Compares arrays and returns the intersection of the two arrays (comparing keys only, using a user-defined key comparison function). |
| array_key_exists() | Checks whether the specified key exists in the array. |
| array_key_first() | Retrieves the first key-value pair of the specified array. |
| array_key_last() | Retrieves the last key-value pair of the specified array. |
| array_keys() | Returns all the keys in the array. |
| array_map() | Applies a user-defined function to each value of the given array and returns the new values. |
| array_merge() | Merges one or more arrays into a single array. |
| array_merge_recursive() | Recursively merges one or more arrays into a single array. |
| array_multisort() | Sorts multiple arrays or multi-dimensional arrays. |
| array_pad() | Inserts a specified number of elements with specified values into an array. |
| array_pop() | Removes the last element from an array (pop). |
| array_product() | Calculates the product of all values in an array. |
| array_push() | Inserts one or more elements at the end of an array (push). |
| array_rand() | Selects one or more random elements from an array and returns the keys. |
| array_reduce() | Iteratively reduces an array to a single string using a user-defined function and returns it. |
| array_replace() | Replaces the values of the first array with those of the following array. |
| array_replace_recursive() | Recursively replaces the values of the first array with those of the following array. |
| array_reverse() | Reverses the order of elements in the original array, creating and returning a new array. |
| array_search() | Searches the 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() | Returns the selected portion of the array. |
| array_splice() | Removes the specified elements from an array and replaces them with other values. |
| array_sum() | Returns the sum of all values in the array. |
| array_udiff() | Compares arrays and returns the difference of the two arrays (comparing values only, using a user-defined key comparison function). |
| array_udiff_assoc() | Compares arrays and returns the difference of the two arrays (comparing keys and values, using a built-in function for keys and a user-defined function for values). |
| array_udiff_uassoc() | Compares arrays and returns the difference of the two arrays (comparing keys and values, using two user-defined key comparison functions). |
| array_uintersect() | Compares arrays and returns the intersection of the two arrays (comparing values only, using a user-defined key comparison function). |
| array_uintersect_assoc() | Compares arrays and returns the intersection of the two arrays (comparing keys and values, using a built-in function for keys and a user-defined function for values). |
| array_uintersect_uassoc() | Compares arrays and returns the intersection of the two arrays (comparing keys and values, using two user-defined key comparison functions). |
| array_unique() | Removes duplicate values from an array. |
| array_unshift() | Inserts one or more elements at the beginning of an array. |
| array_values() | Returns all the values in an array. |
| array_walk() | Applies a user function to every member of an array. |
| array_walk_recursive() | Recursively applies a user function to every member of an array. |
| arsort() | Sorts an associative array in descending order by value. |
| asort() | Sorts an associative array in ascending order by value. |
| compact() | Creates an array containing variable names and their values. |
| count() | Returns the number of elements in the array. |
| current() | Returns the current element in the array. |
| each() | Returns the current key/value pair in the array. |
| end() | Points the internal pointer of the array to the last element. |
| extract() | Imports variables from an array into the current symbol table. |
| in_array() | Checks whether a specified value exists in the array. |
| key() | Retrieves the key from an associative array. |
| krsort() | Sorts an associative array in descending order by key. |
| ksort() | Sorts an associative array in ascending order by key. |
| list() | Assigns the values of an array to some array variables. |
| natcasesort() | Sorts an array using the "natural order" algorithm in a case-insensitive manner. |
| natsort() | Sorts an array using the "natural order" algorithm. |
| next() | Moves the internal pointer of the array back by one position. |
| pos() | Alias of current(). |
| prev() | Rewinds the internal pointer of the array back by one position. |
| range() | Creates an array containing elements within a specified range. |
| reset() | Points the internal pointer of the array to the first element. |
| rsort() | Sorts a numeric array in descending order. |
| shuffle() | Rearranges the elements of an array in random order. |
| sizeof() | Alias of count(). |
| sort() | Sorts a numeric array in ascending order. |
| uasort() | Sorts the values in an array using a user-defined comparison function. |
| uksort() | Sorts the keys in an array using a user-defined comparison function. |
| usort() | Sorts an array using a user-defined comparison function. |