Home  >  Article  >  Backend Development  >  What are the php array operation methods?

What are the php array operation methods?

青灯夜游
青灯夜游Original
2021-04-01 11:35:323451browse

php array operation methods include: array_chunk(), array_pop(), array_push(), array_rand(), array_shift(), array_slice(), array_udiff(), arsort(), etc.

What are the php array operation methods?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP Array function (method) allows developers to access And operate on arrays, and support simple arrays and multi-dimensional arrays.

php array operation method

Function (Method) Description
array() Create an array.
array_change_key_case() Returns an array whose keys are all uppercase or lowercase.
array_chunk() Split an array into new array chunks.
array_column() Returns the value of a single column in the input array.
array_combine() Create a new array by merging two arrays (one for key names and one for key values).
array_count_values() is used to count the number of occurrences of all values ​​in the array.
array_diff() Compares arrays and returns the difference between the two arrays (only comparing key values).
array_diff_assoc() Compare arrays and return the difference between the two arrays (compare key names and key values).
array_diff_key() Compare arrays and return the difference between the two arrays (only comparing key names).
array_diff_uassoc() Compare arrays and return the difference set of two arrays (compare key names and key values, use user-defined key name comparison function).
array_diff_ukey() Compare arrays and return the difference between the two arrays (only compare key names, use user-defined key name comparison function).
array_fill() Fills the array with the given key value.
array_fill_keys() Fills the array with the key value given the specified key name.
array_filter() Use the callback function to filter the elements in the array.
array_flip() Reverse/exchange the key names in the array and the corresponding associated key values.
array_intersect() Compares arrays and returns the intersection of two arrays (only comparing key values).
array_intersect_assoc() Compare arrays and return the intersection of the two arrays (compare key names and key values).
array_intersect_key() Compare arrays and return the intersection of the two arrays (only compare key names).
array_intersect_uassoc() Compare arrays and return the intersection of two arrays (compare key names and key values, use user-defined key name comparison function).
array_intersect_ukey() Compare arrays and return the intersection of the two arrays (only compare key names, use user-defined key name comparison function).
array_key_exists() Check whether the specified key name exists in the array.
array_keys() Returns all key names in the array.
array_map() Apply the user-defined function to each value of the given array and return the new value.
array_merge() Merge one or more arrays into one array.
array_merge_recursive() Recursively merge one or more arrays into one array.
array_multisort() Sort multiple arrays or multidimensional arrays.
array_pad() Inserts the specified number of elements with the specified value into the array.
array_pop() Delete the last element in the array (pop).
array_product() Calculate the product of all values ​​in an array.
array_push() Insert one or more elements into the end of the array (push).
array_rand() Randomly select one or more elements from the array and return the key name.
array_reduce() By using a user-defined function, iteratively reduces the array to a string and returns it.
array_replace() Replace the value of the first array with the value of the subsequent array.
array_replace_recursive() Recursively replace the value of the first array with the value of the subsequent array.
array_reverse() Reverse the order of elements in the original array, create a new array and return it.
array_search() Search for the given value in the array and return the corresponding key name if successful.
array_shift() Deletes the first element in the array and returns the value of the deleted element.
array_slice() Returns the selected portion of the array.
array_splice() Remove the specified element from the array and replace it with other values.
array_sum() Returns the sum of all values ​​in the array.
array_udiff() Compares arrays and returns the difference between the two arrays (only compares key values, using a user-defined key name comparison function).
array_udiff_assoc() Compare arrays and return the difference between the two arrays (compare key names and key values, use built-in functions to compare key names, use user-defined function compares key values).
array_udiff_uassoc() Compare arrays and return the difference set of two arrays (compare key names and key values, use two user-defined key name comparison functions) .
array_uintersect() Compares arrays and returns the intersection of two arrays (only compares key values, using a user-defined key comparison function).
array_uintersect_assoc() Compare arrays and return the intersection of two arrays (compare key names and key values, use built-in functions to compare key names, use user-defined functions Compare key values).
array_uintersect_uassoc() Compare arrays and return the intersection of the two arrays (compare key names and key values, using two user-defined key name comparison functions).
array_unique() Remove duplicate values ​​from the array.
array_unshift() Insert one or more elements at the beginning of the array.
array_values() Returns all the values ​​in the array.
array_walk() Apply a user function to each member of the array.
array_walk_recursive() Applies a user function recursively to each member of an array.
arsort() Sort the associative array in descending order by key value.
asort() Sort the associative array in ascending order by key value.
compact() Creates an array containing variable names and their values.
count() Returns the number of elements in the array.
current() Returns the current element in the array.
each() Returns the current key/value pair in the array.
end() Point the internal pointer of the array to the last element.
extract() Import variables from the array into the current symbol table.
in_array() Checks whether the specified value exists in the array.
key() Get the key name from the associative array.
krsort() Sort the associative array in descending order by key name.
ksort() Sort the associative array in ascending order by key name.
list() Assign the values ​​in the array to some array variables.
natcasesort() Use the "natural sorting" algorithm to sort the array in a case-insensitive manner.
natsort() Sort the array using the "natural sorting" algorithm.
next() Move the internal pointer in the array backward one position.
pos() Alias ​​for current().
prev() Rewind the internal pointer of the array by one bit.
range() Creates an array containing elements in the specified range.
reset() Point the internal pointer of the array to the first element.
rsort() Sort the numeric array in descending order.
shuffle() Rearrange the elements in the array in random order.
sizeof() An alias for count().
sort() Sort the numeric array in ascending order.
uasort() Use a user-defined comparison function to sort the key values ​​in the array.
uksort() Use a user-defined comparison function to sort the key names in the array.
usort() Sort the array using a user-defined comparison function.

Recommended study: "PHP Video Tutorial"

The above is the detailed content of What are the php array operation methods?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn