CodesCompiler
🔍
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact 🚀 Get Started Free

PHP - Array Functions

PHP Array Functions

PHP Array Functionsallow you to interact with and manipulate arrays in various ways. PHP arrays are essential for storing, managing, and operating on sets of variables.

PHP supports simple and multi-dimensional arrays and can be either user created or created by another function. You can use these functions to modify, sort, add, remove or search elements in an array.

Installation

There is no installation needed to use PHP array functions; they are part of the PHP core and comes along with standard PHP installation.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

PHP Array Functions

Following table lists down all the functions related to PHP Array. Here column version indicates the earliest version of PHP that supports the function.

Sr.NoFunction & DescriptionVersion1array()Create an array4.2.02array_change_key_case()Returns an array with all keys in lowercase or uppercase4.2.03array_chunk()Splits an array into chunks of arrays4.2.03array_column()Return the values from a single column in the input array5.5.04array_combine()Creates an array by using one array for keys and another for its values55array_count_values()Returns an array with the number of occurrences for each value46array_diff()Compares array values, and returns the differences47array_diff_assoc()Compares array keys and values, and returns the differences48array_diff_key()Compares array keys, and returns the differences59array_diff_uassoc()Compares array keys and values, with an additional user-made function check, and returns the differences510array_diff_ukey()Compares array keys, with an additional user-made function check, and returns the differences511array_fill()Fills an array with values412array_fill_keys()Fill an array with values, specifying keys513array_filter()Filters elements of an array using a user-made function414array_flip()Exchanges all keys with their associated values in an array415array_intersect()Compares array values, and returns the matches416array_intersect_assoc()Compares array keys and values, and returns the matches417array_intersect_key()Compares array keys, and returns the matches518array_intersect_uassoc()Compares array keys and values, with an additional user-made function check, and returns the matches519array_intersect_ukey()Compares array keys, with an additional user-made function check, and returns the matches520array_key_exists()Checks if the specified key exists in the array421array_keys()Returns all the keys of an array422array_map()Sends each value of an array to a user-made function, which returns new values423array_merge()Merges one or more arrays into one array424array_merge_recursive()Merges one or more arrays into one array425array_multisort()Sorts multiple or multi-dimensional arrays426array_pad()Inserts a specified number of items, with a specified value, to an array427array_pop()Deletes the last element of an array428array_product()Calculates the product of the values in an array529array_push()Inserts one or more elements to the end of an array430array_rand()Returns one or more random keys from an array431array_reduce()Returns an array as a string, using a user-defined function432array_reverse()Returns an array in the reverse order433array_search()Searches an array for a given value and returns the key434array_shift()Removes the first element from an array, and returns the value of the removed element435array_slice()Returns selected parts of an array436array_splice()Removes and replaces specified elements of an array437array_sum()Returns the sum of the values in an array438array_udiff()Compares array values in a user-made function and returns an array539array_udiff_assoc()Compares array keys, and compares array values in a user-made function, and returns an array540array_udiff_uassoc()Compares array keys and array values in user-made functions, and returns an array541array_uintersect()Compares array values in a user-made function and returns an array542array_uintersect_assoc()Compares array keys, and compares array values in a user-made function, and returns an array543array_uintersect_uassoc()Compares array keys and array values in user-made functions, and returns an array544array_unique()Removes duplicate values from an array445array_unshift()Adds one or more elements to the beginning of an array446array_values()Returns all the values of an array447array_walk()Applies a user function to every member of an array348array_walk_recursive()Applies a user function recursively to every member of an array549arsort()Sorts an array in reverse order and maintain index association350asort()Sorts an array and maintain index association351compact()Create array containing variables and their values452count()Counts elements in an array, or properties in an object353current()Returns the current element in an array354each()Returns the current key and value pair from an array355end()Sets the internal pointer of an array to its last element356extract()Imports variables into the current symbol table from an array357in_array()Checks if a specified value exists in an array458key()Fetches a key from an array359krsort()Sorts an array by key in reverse order360ksort()Sorts an array by key361list()Assigns variables as if they were an array362natcasesort()Sorts an array using a case insensitive “natural order” algorithm463natsort()Sorts an array using a “natural order” algorithm464next()Advance the internal array pointer of an array365pos()Alias of current()366prev()Rewinds the internal array pointer367range()Creates an array containing a range of elements368reset()Sets the internal pointer of an array to its first element369rsort()Sorts an array in reverse order370shuffle()Shuffles an array371sizeof()Alias of count()372sort()Sorts an array373uasort()Sorts an array with a user-defined function and maintain index association374uksort()Sorts an array by keys using a user-defined function375usort()Sorts an array by values using a user-defined function3

PHP Array Constants

Sr.NoConstant & Description1CASE_LOWERUsed with array_change_key_case() to convert array keys to lower case2CASE_UPPERUsed with array_change_key_case() to convert array keys to upper case3SORT_ASCUsed with array_multisort() to sort in ascending order4SORT_DESCUsed with array_multisort() to sort in descending order5SORT_REGULARUsed to compare items normally6SORT_NUMERICUsed to compare items numerically7SORT_STRINGUsed to compare items as strings8SORT_LOCALE_STRINGUsed to compare items as strings, based on the current locale9COUNT_NORMAL10COUNT_RECURSIVE11EXTR_OVERWRITE12EXTR_SKIP13EXTR_PREFIX_SAME14EXTR_PREFIX_ALL15EXTR_PREFIX_INVALID16EXTR_PREFIX_IF_EXISTS17EXTR_IF_EXISTS18EXTR_REFS

php_function_reference.htm