PHP Array Introduction
The array functions allow you to manipulate arrays.
PHP supports both simple and multi-dimensional arrays. There are also specific functions for populating arrays from database queries.
Installation
The array functions are part of the PHP core. There is no installation needed to use these functions.
PHP Array Functions
PHP: indicates the earliest version of PHP that supports the function.
Function | Description |
array() | Creates an array |
array_change_key_case() | Returns an array with all keys in lowercase or uppercase |
array_chunk() | Splits an array into chunks of arrays |
array_combine() | Creates an array by using one array for keys and another for its values |
array_count_values() | Returns an array with the number of occurrences for each value |
Compares array values, and returns the differences | |
Compares array keys and values, and returns the differences | |
Compares array keys, and returns the differences | |
Compares array keys and values, with an additional user-made function check, and returns the differences | |
Compares array keys, with an additional user-made function check, and returns the differences | |
Fills an array with values | |
Filters elements of an array using a user-made function | |
Exchanges all keys with their associated values in an array | |
Compares array values, and returns the matches | |
Compares array keys and values, and returns the matches | |
Compares array keys, and returns the matches | |
Compares array keys and values, with an additional user-made function check, and returns the matches | |
Compares array keys, with an additional user-made function check, and returns the matches | |
Checks if the specified key exists in the array | |
Returns all the keys of an array | |
Sends each value of an array to a user-made function, which returns new values | |
Merges one or more arrays into one array | |
Merges one or more arrays into one array | |
Sorts multiple or multi-dimensional arrays | |
Inserts a specified number of items, with a specified value, to an array | |
Deletes the last element of an array | |
Calculates the product of the values in an array | |
Inserts one or more elements to the end of an array | |
Returns one or more random keys from an array |
Returns an array as a string, using a user-defined function | |
Returns an array in the reverse order | |
Searches an array for a given value and returns the key | |
Removes the first element from an array, and returns the value of the removed element | |
Returns selected parts of an array | |
Removes and replaces specified elements of an array | |
Returns the sum of the values in an array | |
Compares array values in a user-made function and returns an array | |
Compares array keys, and compares array values in a user-made function, and returns an array | |
Compares array keys and array values in user-made functions, and returns an array | |
Compares array values in a user-made function and returns an array | |
Compares array keys, and compares array values in a user-made function, and returns an array | |
Compares array keys and array values in user-made functions, and returns an array | |
Removes duplicate values from an array | |
Adds one or more elements to the beginning of an array | |
Returns all the values of an array | |
Applies a user function to every member of an array | |
Applies a user function recursively to every member of an array | |
Sorts an array in reverse order and maintain index association | |
Sorts an array and maintain index association | |
Create array containing variables and their values | |
Counts elements in an array, or properties in an object | |
Returns the current element in an array | |
Returns the current key and value pair from an array | |
Sets the internal pointer of an array to its last element | |
Imports variables into the current symbol table from an array | |
Checks if a specified value exists in an array | |
Fetches a key from an array | |
Sorts an array by key in reverse order | |
Sorts an array by key | |
Assigns variables as if they were an array | |
Sorts an array using a case insensitive "natural order" algorithm | |
Sorts an array using a "natural order" algorithm | |
Advance the internal array pointer of an array | |
Alias of current() | |
Rewinds the internal array pointer | |
Creates an array containing a range of elements | |
Sets the internal pointer of an array to its first element | |
Sorts an array in reverse order | |
Shuffles an array | |
Alias of count() | |
Sorts an array | |
Sorts an array with a user-defined function and maintain index association | |
Sorts an array by keys using a user-defined function | |
Sorts an array by values using a user-defined function |