PHP array functions

Source: Internet
Author: User

1, the key value function Array_values () returns the array element value, forming a new index array

2, Array_keys () returns all the key names of the array, forming an indexed array

3, In_array () check if a value exists in the array

4, array_key_exists () can check whether the given key name or index exists in the array, Isset () can also, but the null value does not return True

5, Array_flip () reverses the keys and values in the array

6. Array_reverse () returns the order of elements in the array

7, COUNT () counts the number of elements in an array, or the number of attributes in an object

8, Array_count_values () counts the number of occurrences of all the values in the array, the key name in the returned array is the value of the original array, and the key value is the number of occurrences of the value in the original array

9. Arrry_unique () deletes duplicate values in the array and returns a new array with no duplicate values

10. Callback function Array_filter (), returns the new array after the callback function is filtered

11, Array_walk (), execute callback function, successfully return true, manipulate the values in the array, can be used & parameters

12, Array_map (), executes the callback function, returns a new array after processing, you can manipulate multiple arrays, the number of arrays should be the same as callback function parameters

13, sorting function according to the elements in the array from small to large sort () or from large to small rsort () sort

14. Sort Ksort () according to the key name in the array, Krsort ()

15, Asort () and Arsort () are also sorted by value, but retain the relationship of the original key name and value

16. Natural sort (1-9 A-Z) natsort () Natcasesort ()

17, custom sort above can define callback function to sort by itself

18, split merge decomposition junction array array_slice (), take a certain value according to the condition and return

19, Array_splice (), according to the conditions to remove a value and delete

20, Array_combine () merge two arrays back, one as the key name, one as the value, if the number of two arrays is not equal, returns false

21. Array_merge () merges one or more arrays into an array, followed by the key name, and if the index array is re-indexed, the array can be combined with +, but not later

22, Array_intersect () computes the intersection of the array and returns

23, Array_diff () returns the difference between the sets in the array

34. Data structure function stack (LIFO) Array_push () and Array_pop ()

35. Queue (FIFO) Array_shift ()

36. Other Array_rand () randomly selects one or more elements from an array and returns the key name of the element

37. Shuffle () scrambled array order

38, Array_sum () returns the sum of the values in the array

39, Range () creates and returns an array containing the elements of the specified range

40. Delete an element in the array unset (), note that the index is not rebuilt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.