Array Functions

PHP Array Functions allow 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 may be either user created or created by another function.

Installation

There is no installation needed to use PHP array functions; they are part of the PHP core and comes alongwith 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 & DescriptionVersion
1array()Create an array4.2.0
2array_change_key_case()Returns an array with all keys in lowercase or uppercase4.2.0
3array_chunk()Splits an array into chunks of arrays4.2.0
3array_column()Return the values from a single column in the input array5.5.0
4array_combine()Creates an array by using one array for keys and another for its values5
5array_count_values()Returns an array with the number of occurrences for each value4
6array_diff()Compares array values, and returns the differences4
7array_diff_assoc()Compares array keys and values, and returns the differences4
8array_diff_key()Compares array keys, and returns the differences5
9array_diff_uassoc()Compares array keys and values, with an additional user-made function check, and returns the differences5
10array_diff_ukey()Compares array keys, with an additional user-made function check, and returns the differences5
11array_fill()Fills an array with values4
12array_fill_keys()Fill an array with values, specifying keys5
13array_filter()Filters elements of an array using a user-made function4
14array_flip()Exchanges all keys with their associated values in an array4
15array_intersect()Compares array values, and returns the matches4
16array_intersect_assoc()Compares array keys and values, and returns the matches4
17array_intersect_key()Compares array keys, and returns the matches5
18array_intersect_uassoc()Compares array keys and values, with an additional user-made function check, and returns the matches5
19array_intersect_ukey()Compares array keys, with an additional user-made function check, and returns the matches5
20array_key_exists()Checks if the specified key exists in the array4
21array_keys()Returns all the keys of an array4
22array_map()Sends each value of an array to a user-made function, which returns new values4
23array_merge()Merges one or more arrays into one array4
24array_merge_recursive()Merges one or more arrays into one array4
25array_multisort()Sorts multiple or multi-dimensional arrays4
26array_pad()Inserts a specified number of items, with a specified value, to an array4
27array_pop()Deletes the last element of an array4
28array_product()Calculates the product of the values in an array5
29array_push()Inserts one or more elements to the end of an array4
30array_rand()Returns one or more random keys from an array4
31array_reduce()Returns an array as a string, using a user-defined function4
32array_reverse()Returns an array in the reverse order4
33array_search()Searches an array for a given value and returns the key4
34array_shift()Removes the first element from an array, and returns the value of the removed element4
35array_slice()Returns selected parts of an array4
36array_splice()Removes and replaces specified elements of an array4
37array_sum()Returns the sum of the values in an array4
38array_udiff()Compares array values in a user-made function and returns an array5
39array_udiff_assoc()Compares array keys, and compares array values in a user-made function, and returns an array5
40array_udiff_uassoc()Compares array keys and array values in user-made functions, and returns an array5
41array_uintersect()Compares array values in a user-made function and returns an array5
42array_uintersect_assoc()Compares array keys, and compares array values in a user-made function, and returns an array5
43array_uintersect_uassoc()Compares array keys and array values in user-made functions, and returns an array5
44array_unique()Removes duplicate values from an array4
45array_unshift()Adds one or more elements to the beginning of an array4
46array_values()Returns all the values of an array4
47array_walk()Applies a user function to every member of an array3
48array_walk_recursive()Applies a user function recursively to every member of an array5
49arsort()Sorts an array in reverse order and maintain index association3
50asort()Sorts an array and maintain index association3
51compact()Create array containing variables and their values4
52count()Counts elements in an array, or properties in an object3
53current()Returns the current element in an array3
54each()Returns the current key and value pair from an array3
55end()Sets the internal pointer of an array to its last element3
56extract()Imports variables into the current symbol table from an array3
57in_array()Checks if a specified value exists in an array4
58key()Fetches a key from an array3
59krsort()Sorts an array by key in reverse order3
60ksort()Sorts an array by key3
61list()Assigns variables as if they were an array3
62natcasesort()Sorts an array using a case insensitive “natural order” algorithm4
63natsort()Sorts an array using a “natural order” algorithm4
64next()Advance the internal array pointer of an array3
65pos()Alias of current()3
66prev()Rewinds the internal array pointer3
67range()Creates an array containing a range of elements3
68reset()Sets the internal pointer of an array to its first element3
69rsort()Sorts an array in reverse order3
70shuffle()Shuffles an array3
71sizeof()Alias of count()3
72sort()Sorts an array3
73uasort()Sorts an array with a user-defined function and maintain index association3
74uksort()Sorts an array by keys using a user-defined function3
75usort()Sorts an array by values using a user-defined function3

PHP Array Constants

Sr.NoConstant & Description
1CASE_LOWERUsed with array_change_key_case() to convert array keys to lower case
2CASE_UPPERUsed with array_change_key_case() to convert array keys to upper case
3SORT_ASCUsed with array_multisort() to sort in ascending order
4SORT_DESCUsed with array_multisort() to sort in descending order
5SORT_REGULARUsed to compare items normally
6SORT_NUMERICUsed to compare items numerically
7SORT_STRINGUsed to compare items as strings
8SORT_LOCALE_STRINGUsed to compare items as strings, based on the current locale
9COUNT_NORMAL
10COUNT_RECURSIVE
11EXTR_OVERWRITE
12EXTR_SKIP
13EXTR_PREFIX_SAME
14EXTR_PREFIX_ALL
15EXTR_PREFIX_INVALID
16EXTR_PREFIX_IF_EXISTS
17EXTR_IF_EXISTS
18EXTR_REFS

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *