PHP Array functions
PHP: indicates the earliest PHP version that supports this function.
| Function |
Description |
PHP |
| Array () |
Create an array. |
3 |
| Array_change_key_case () |
Returns an array with uppercase or lowercase keys. |
4 |
| Array_chunk () |
Splits an array into new array blocks. |
4 |
| Array_combine () |
Create a new array by combining two arrays. |
5 |
| Array_count_values () |
Used to count the number of times all values appear in the array. |
4 |
| Array_diff () |
Returns the number of difference sets of two arrays. |
4 |
| Array_diff_assoc () |
Compare the key name and key value, and return the number groups of the two arrays. |
4 |
| Array_diff_key () |
Compare the key name, and return the number groups of the two arrays. |
5 |
| Array_diff_uassoc () |
You can use the callback function provided by the user to perform an index check to calculate the array's difference set. |
5 |
| Array_diff_ukey () |
Use the callback function to compare the difference set of the calculated array with the key name. |
5 |
| Array_fill () |
Fill the array with the given value. |
4 |
| Array_filter () |
Use the callback function to filter elements in the array. |
4 |
| Array_flip () |
Exchange keys and values in the array. |
4 |
| Array_intersect () |
Calculates the intersection of arrays. |
4 |
| Array_intersect_assoc () |
Compare the key name and key value, and return the intersection array of the two arrays. |
4 |
| Array_intersect_key () |
Use the key name to compare and calculate the intersection of arrays. |
5 |
| Array_intersect_uassoc () |
Check and calculate the intersection of arrays with indexes, and use the callback function to compare indexes. |
5 |
| Array_intersect_ukey () |
Use the callback function to compare the key names to calculate the intersection of arrays. |
5 |
| Array_key_exists () |
Check whether the given key name or index exists in the array. |
4 |
| Array_keys () |
Returns all the key names in the array. |
4 |
| Array_map () |
The callback function acts on the units of the given array. |
4 |
| Array_merge () |
Combine one or more numbers into an array. |
4 |
| Array_merge_recursive () |
Recursively merges one or more arrays. |
4 |
| Array_multisort () |
Sorts multiple arrays or multi-dimensional arrays. |
4 |
| Array_pad () |
Fill the array with values to the specified length. |
4 |
| Array_pop () |
Bring up the last unit of the array (out stack ). |
4 |
| Array_product () |
Calculates the product of all values in the array. |
5 |
| Array_push () |
Push one or more units (elements) to the end of the array (into the stack ). |
4 |
| Array_rand () |
Randomly selects one or more elements from the array and returns the result. |
4 |
| Array_reduce () |
Use the callback function to iteratively simplify the array to a single value. |
4 |
| Array_reverse () |
Flip the elements in the original array sequentially, create a new array, and return it. |
4 |
| Array_search () |
Search for the given value in the array. If the value is successful, the corresponding key name is returned. |
4 |
| Array_shift () |
Delete the first element in the array and return the value of the deleted element. |
4 |
| Array_slice () |
Extract a value from the array based on the conditions and return it. |
4 |
| Array_splice () |
Remove part of the array and replace it with other values. |
4 |
| Array_sum () |
Calculates the sum of all values in the array. |
4 |
| Array_udiff () |
Use the callback function to compare data to calculate the difference set of the array. |
5 |
| Array_udiff_assoc () |
Calculate the difference set of the array with index check, and use the callback function to compare the data. |
5 |
| Array_udiff_uassoc () |
Use the callback function to compare data and indexes. |
5 |
| Array_uintersect () |
Calculate the intersection of arrays and use the callback function to compare the data. |
5 |
| Array_uintersect_assoc () |
Check and calculate the intersection of arrays with indexes, and use the callback function to compare data. |
5 |
| Array_uintersect_uassoc () |
Use the callback function to compare data and indexes. |
5 |
| Array_unique () |
Delete repeated values in the array. |
4 |
| Array_unshift () |
Insert one or more elements at the beginning of the array. |
4 |
| Array_values () |
Returns all values in the array. |
4 |
| Array_walk () |
Apply user functions to each member in the array. |
3 |
| Array_pai_recursive () |
Recursively apply user functions to each member in the array. |
5 |
| Arsort () |
Sort the array in reverse order and maintain the index relationship. |
3 |
| Asort () |
Sorts the array and maintains the index relationship. |
3 |
| Compact () |
Create an array, including the variable names and their values. |
4 |
| Count () |
Calculates the number of elements in an array or the number of attributes in an object. |
3 |
| Current () |
Returns the current element in the array. |
3 |
| Each () |
Returns the current key/value pair in the array and moves the array pointer one step forward. |
3 |
| End () |
Point the internal pointer of the array to the last element. |
3 |
| Extract () |
Import the variable from the array to the current symbol table. |
3 |
| In_array () |
Check whether the specified value exists in the array. |
4 |
| Key () |
Obtain the key name from the joined array. |
3 |
| Krsort () |
Sort the array in reverse order by key name. |
3 |
| Ksort () |
Sort the array by key name. |
3 |
| List () |
Assign values in the array to some variables. |
3 |
| Natcasesort () |
Use the "natural sorting" algorithm to sort arrays by case-insensitive letters. |
4 |
| Natsort () |
Sort arrays using the "natural sorting" algorithm. |
4 |
| Next () |
Move the internal pointer in the array one by one. |
3 |
| Pos () |
The alias of current. |
3 |
| Prev () |
Returns the internal pointer of the array to one position. |
3 |
| Range () |
Creates an array containing elements in a specified range. |
3 |
| Reset () |
Points the internal pointer of the array to the first element. |
3 |
| Rsort () |
Sorts arrays in reverse order. |
3 |
| Shuffle () |
Sorts the elements in the array in random order. |
3 |
| Sizeof () |
The alias of count. |
3 |
| Sort () |
Sorts arrays. |
3 |
| Uasort () |
Use the custom comparison function to sort the values in the array and maintain the index Association. |
3 |
| Uksort () |
Sort the key names in the array using the custom comparison function. |
3 |
| Usort () |
Sort the values in the array using the user-defined comparison function. |
3 |
PHP Array constant
PHP: indicates the earliest PHP version that supports this constant.
| Constant |
Description |
PHP |
| CASE_LOWER |
Use array_change_key_case () to convert the array key name to lowercase letters. |
|
| CASE_UPPER |
Convert the array key name into uppercase letters in array_change_key_case. |
|
| SORT_ASC |
It is used in the array_multisort () function to sort it in ascending order. |
|
| SORT_DESC |
It is used in the array_multisort () function to sort it in descending order. |
|
| SORT_REGULAR |
Used to compare objects. |
|
| SORT_NUMERIC |
Used to compare the value of an object. |
|
| SORT_STRING |
It is used to compare strings of objects. |
|
| SORT_LOCALE_STRING |
Compares strings of objects based on the current region. |
4 |
| COUNT_NORMAL |
|
|
| COUNT_RECURSIVE |
|
|
| EXTR_OVERWRITE |
|
|
| EXTR_SKIP |
|
|
| EXTR_PREFIX_SAME |
|
|
| EXTR_PREFIX_ALL |
|
|
| EXTR_PREFIX_INVALID |
|
|
| EXTR_PREFIX_IF_EXISTS |
|
|
| EXTR_IF_EXISTS |
|
|
| EXTR_REFS |
|
|
Favorite common php Tutorial array operation functions
Search for a specific value in the array. If yes, return TRUE. Otherwise, return FALSE.
Boolean in_array (mixed needle, array haystack [, boolean strict])
Find a specified key in the array. If yes, return TRUE. Otherwise, return FALSE.
Boolean array_eky_exists (mixed key, array)
Search for a specific value in the array. If yes, return TRUE. Otherwise, return FALSE.
Boolean array_search (mixed needle, array haystack [, boolean strict])
Obtains a new array composed of all the keys in the array.
Array array_keys (array [, mixed search_value])
Obtains a new array composed of all values of the array.
Array array_values (array)
Determine the array size
Integer count (array [, int mode])
Integer sizeof (array [, int mode])
Count the occurrence frequency of array elements
Array array_count_values (array)
Deletes repeated values in an array and returns an array consisting of unique values.
Array array_unique (array)
Returns the element order of the array. If the value of preserve_key is TRUE, the order of the key values of the array remains unchanged.
Array array_reverse (array [, boolean preserve_key])
Replace the array key and value
Array array_flip (array)
Sort arrays sequentially. The sort_flags parameter is optional. Default behavior.
SORT_NUMBERIC, sorted by numerical value, useful for sorting integers or floating-point numbers
SORT_REGULAR, sorted by ASCII value
SORT_STRING, which is sorted by the correct order of the nearest person
The key-value sequence of the asort function remains unchanged.
Void sort (array [, int sort_flags])
Void asort (array [, int sort_flags])
Array sorting in reverse order. The sort_flags parameter is optional. Default behavior.
SORT_NUMBERIC, sorted by numerical value, useful for sorting integers or floating-point numbers
SORT_REGULAR, sorted by ASCII value
SORT_STRING, which is sorted by the correct order of the nearest person
The order of the key values of the arsort function remains unchanged.
Void rsort (array [, int sort_flags])
Void arsort (array [, int sort_flags])
Natural sorting of arrays
Void natsort (array)
Case-insensitive natural sorting
Void natcasesort (array)
Sort the key-value pairs in an array
Boolean ksort (array [, int sort_flags])
Sort the key-value pairs in reverse order.
Boolean krsort (array [, int sort_flags])
Sort by user-defined order
Void usort (array, callback function_name)
Merges the arrays to return a Union array. Array_merge overwrites the front, and array_merge_recursive is merged.
Array array_merge (array array1 [array array2…]) // More than one
Array array_merge_recursive (array array1, array array2 [, array…]) // More than two
Key and value form a new array
Array array_combine (array key, array value)
Returns a part of the array, starting from the offset and ending at the offse + length position.
Array array_slice (array, int offset [, int length])
Delete all elements starting from offset to ending with offset + length, and return the deleted elements as arrays.
Array array_splice (array, int offset [, int length [, array peplacement])
Returns the intersection of arrays. The key value is the key value in the first array.
Array array_intersect (array array1, array array2 [, arrayN…])
The intersection of the array contains the same key value. The key value is the key value of the first array.
Array array_intersect_assoc (array array1, array array2 [, arrayN…])
Evaluate the difference set of the array. The first array does not have values in other arrays.
Array array_diff (array array1, array array2 [, arrayN…])
Evaluate the difference set of the array. The first array does not have the same key value in other arrays.
Array array_diffassoc (array array1, array array2 [, arrayN…])
Returns one or more key values in the array.
Mixed array_rand (array [, int num_entries])
Shuffling function
Void shuffle (array input_array)
Summation of values in the array
Mixed array_sum (array );
Splits an array into a multi-dimensional array that contains size elements.
Array array_chunk (array, int size [, boolean preserve_keys])