Common functions for php arrays
Because there are so many array functions, many of them are labeled in English. There are also some array functions that are less commonly used.
Therefore, we have summarized the most commonly used array functions with you, so that you can remember which function you must mention at any time. Use directly.
Please use these functions several times against the examples in the manual. Requirements:dictation level.
In the future, when reading and writing any code, there is no need to reflect for a long time. Using these functions directly is the basic quality of a programmer.
These functions are also the most frequently asked questions in basic interviews.
Function name | Function | |
---|---|---|
Generate an array, using the value of one array as the key name and the value of the other array as the value | ||
Create and return an array containing the specified range of elements. | ||
Create an array consisting of the variables taken by the parameters | ||
Generate an array with the given value | ||
##array_merge() |
||
array_slice() |
||
##array_diff() | Returns the difference array of two arrays
||
array_search() | Search for the given value in the array, and if successful, return the corresponding key name
||
array_splice() | Remove part of the array and replace it with other values
||
##array_sum() | Calculate the sum of all values in the array |
|
in_array() | Check whether a certain value exists in the array |
|
array_key_exists() | Check whether the given key name or index exists in the array |
|
shuffle() | Shuffle the array and keep the key values |
|
count() | Calculate the number of cells in the array or the number of attributes in the object |
|
##array_flip() | Return an array with key values reversed |
|
array_keys() | Returns all the keys of the array to form an array |
|
##array_values() | Returns all the values in the array to form an array | |
array_reverse() | Returns an array with the elements in reverse order | |
##array_count_values() | Count the number of occurrences of all values in the array | |
Randomly draw from the array One or more elements, note the key name | ||
Delete duplicate values and return the remaining array | ||
Sort the values of the given array in ascending order, without retaining key names | ||
Reverse sort the array without retaining key names | ||
Sort the array and keep the index relationship | ||
##natsort() |
||
##natcasesort() | Natural sorting, not case sensitive
||
array_filter() | Remove empty elements or predetermined elements in the array | |
extract | Change keys into variable names and values into variable values |