PHP 5 ArrayFunctions


PHP Array Introduction

PHP Array functions allow you to access and manipulate arrays.

Simple and multidimensional arrays are supported.


Installation

PHP Array functions are part of the PHP core. You can use these functions without installation.


PHP 5 Array Functions

Function Description
array() Creates an array.
array_change_key_case() Returns an array with all keys in uppercase or lowercase.
array_chunk() Splits an array into new chunks.
array_column() Returns the values of a single column in the input array.
array_combine() Creates a new array by merging two arrays (one of keys, one of values).
array_count_values() Counts all occurrences of values in an array.
array_diff() Compares arrays and returns the difference (compares only values).
array_diff_assoc() Compares arrays and returns the difference (compares both keys and values).
array_diff_key() Compares arrays and returns the difference (compares only keys).
array_diff_uassoc() Compares arrays and returns the difference (compares keys and values, using a user-defined key comparison function).
array_diff_ukey() Compares arrays and returns the difference (compares only keys, using a user-defined key comparison function).
array_fill() Fills an array with the given value.
array_fill_keys() Fills an array with values, specifying keys.
array_filter() Filters elements of an array using a callback function.
array_flip() Reverses/swaps keys and their associated values in an array.
array_intersect() Compares arrays and returns the intersection (compares only values).
array_intersect_assoc() Compares arrays and returns the intersection (compares both keys and values).
array_intersect_key() Compares arrays and returns the intersection (compares only keys).
array_intersect_uassoc() Compares arrays and returns the intersection (compares keys and values, using a user-defined key comparison function).
array_intersect_ukey() Compares arrays and returns the intersection (compares only keys, using a user-defined key comparison function).
array_key_exists() Checks if the specified key exists in an array.
array_key_first() Gets the first value of the specified array.
array_key_last() Gets the last value of the specified array.
array_keys() Returns all keys of an array.
array_map() Applies a user-defined function to each value of a given array and returns the new values.
array_merge() Merges one or more arrays into one array.
array_merge_recursive() Recursively merges one or more arrays into one array.
array_multisort() Sorts multiple arrays or multidimensional arrays.
array_pad() Inserts a specified number of elements with a specified value into an array.
array_pop() Deletes the last element of an array (pop).
array_product() Computes 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 string using a user-defined function, and returns it.
array_replace() Replaces the values of the first array with values from subsequent arrays.
array_replace_recursive() Recursively replaces the values of the first array with values from subsequent arrays.
array_reverse() Reverses the order of elements in the original array, creates and returns a new array.
array_search() Searches an array for a given value and returns the corresponding key if successful.
array_shift() Deletes the first element of an array and returns the value of the removed element.
array_slice() Returns a selected portion of an array.
array_splice() Removes specified elements from an array and replaces them with other values.
array_sum() Returns the sum of all values in an array.
array_udiff() Compares arrays and returns the difference (compares only values, using a user-defined value comparison function).
array_udiff_assoc() Compares arrays and returns the difference (compares keys and values; uses built-in function to compare keys, and user-defined function to compare values).
array_udiff_uassoc() Compares arrays and returns the difference (compares keys and values, using two user-defined comparison functions).
array_uintersect() Compares arrays and returns the intersection (compares only values, using a user-defined value comparison function).
array_uintersect_assoc() Compares arrays and returns the intersection (compares keys and values; uses built-in function to compare keys, and user-defined function to compare values).
array_uintersect_uassoc() Compares arrays and returns the intersection (compares keys and values, using two user-defined 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 values of an array.
array_walk() Applies a user function to each member of an array.
array_walk_recursive() Recursively applies a user function to each member of an array.
arsort() Sorts an associative array in descending order by values.
asort() Sorts an associative array in ascending order by values.
compact() Creates an array containing variable names and their values.
count() Returns the number of elements in an array.
current() Returns the current element in an array.
each() Returns the current key/value pair in an array.
end() Points the internal pointer of an array to the last element.
extract() Imports variables from an array into the current symbol table.
in_array() Checks if a specified value exists in an array.
key() Gets keys from an associative array.
krsort() Sorts an associative array in descending order by keys.
ksort() Sorts an associative array in ascending order by keys.
list() Assigns values from an array to variables.
natcasesort() Sorts an array using a "natural order" algorithm without case sensitivity.
natsort() Sorts an array using a "natural order" algorithm.
next() Moves the internal pointer of an array forward by one.
pos() Alias of current().
prev() Moves the internal pointer of an array backward by one.
range() Creates an array containing a specified range of elements.
reset() Points the internal pointer of an 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 values in an array using a user-defined comparison function.
uksort() Sorts keys in an array using a user-defined comparison function.
usort() Sorts an array using a user-defined comparison function.
Other Extensions