Commonly used array functions in PHP

Source: Internet
Author: User
1. boolean sort (array target_array [, int sort_flags]): sort by number and letter
2. boolean rsort (array target_array [, int sort_flags]): sorts array elements in descending order.
3. Void asort (array target_array [, int sort_flags]): sorts associated arrays (Retain the original index relationship)
4. Void arsort (array target_array [, int sort_flags]): sort the associated arrays in descending order (Retain the original index relationship)
5. Integer ksort (array target_array [, int sort_flags]): sort by index value
6. Integer krsort (array target_array [, int sort_flags]): sort by index value in descending order.
7. usort (): sort by user-defined method
8. boolean array_multisort (array target_array [, mixed Arg [, mixed arg2. ..]): sorts multiple arrays at a time.
9. natsort (): Natural sorting
10. matcasesort (): Natural sorting (Case Insensitive)
11. boolean shuffle (array target_array): sorts arrays randomly.
12. array array_reverse (array target_array [, Boolean preserve_keys]): reverse the elements in the array
13. array array_flip (array target_array): swap the index of the array with its element value.
14. Mixed current (array target_array): gets the element value specified by the current pointer in the array.
15. Mixed Next (array target_array): Move the pointer of the array one bit backward.
16. Mixed Prev (array target_array): Move the pointer pair of the array one by one
17. Mixed reset (array target_array): the pointer is set to the starting position of the array.
18. Mixed end (array target_array): the pointer is set to the last element of the array.
19. array each (array target_array): obtains the current "index/element value" pair in the array.
20. Mixed key (array target_array): gets the index value of the element pointed to by the current pointer of the array.
21. boolean array_walk (array target_array, callback function [, mixed userdata]): process each element in the array in the same way
22. Mixed array_reduce (array target_total, callback function [, int initial]): Apply the custom function to each element in the array in sequence.
23. Void list (mixed varname [, mixed varname...]): Extracts multiple values from one array at a time.
24. Integer count (array target_array [, int mode]): calculates the number of elements in the array. Sizeof () is the alias of the function.
25. array array_count_values (array target_array): counts the frequency of array elements.
26. array array_unique (array target_array): deletes repeated element values in the array. The index value of the original array is not damaged.

27. array array_combine (array keys, array values): generates a new array based on the parameter array. The two parameters must be of the same size and cannot be empty.

28. array array_merge (array target_array1, array target_array2, [, array target_array3...]): combines multiple numbers into a new array. If it is not an associated array

Add; if it is an associated array, the subsequent elements overwrite the previous elements.

29. array array_merge_recursive (array target_array1, array target_array2 [, array target_array3...]): recursively merges multiple arrays into a new array. And array_merge ()

The function is similar. If the merge operation involves duplicate indexes, instead of overwriting the previous elements, the duplicate index name is used as the array name to form a new array, it will become a multi-dimensional array.

30. array array_slice (array target_array, int offset [, int length]): obtains some elements in the array.

31. array array_splice (array target_array, int offset [, int length [, array replacement]): deletes the specified array element, and returns the deleted or replaced element.

. Others are similar to array_slice

32. array array_intersect (array target_array1, array target_array2 [, array target_array3...]): Obtain the elements repeated in multiple (actually all arrays in parentheses) arrays.

Prime value. (Please remember that it is an element value, not an index value), and returns an array, where the element value is the same, and the index value is the first, that is, target_array1. indexes are not considered.

33. array array_intersect_assoc (array target_array1, array target_array2 [, array target_array3...]): it is basically consistent with array_intersect, but it needs to be considered

The index and element value are the same, and the returned value is an array.

34. array array_diff (array target_array1, array target_array2 [, array target_array3...]): obtains element values that are not repeated in other arrays. That is, only

If target_array1 appears, it cannot appear in target_array2 or target_array3. Only the element value is considered, and the index value is not considered.

35. array array_diff_assoc (array target_array1, array target_array2 [, array target_array3...]): it is basically the same as array_diff, but it requires no element or index.

Repeat it.

36. Mixed array_sum (array target_array): sums all values in the array. The values in target_array must be integers or floating-point numbers. Other types of data will be ignored.

37. Mixed array_rand (array target_array [, int num]): returns one or more indexes of an array at random.

38. array array_chunk (array target_array, int size [, Boolean preserve_key]): splits an array into multiple arrays.

39. int array_push (array target_array, mixed variable1 [, mixed variable2...]): add the value of the specified variable to the end of the array. Note that it does not support the insertion of the associated array,

Only element values.

40. Mixed array_pop (array target_array): obtains the value of the last element in the array, and deletes the element from the array.

41. Mixed array_shift (array target_array): obtains the value of the first element in the array. Other elements move forward. If the value is a digital index, the indexes decrease and the associated arrays are not affected.

42. Int array_unshift (array target_array, mixed variable1 [, mixed variable2...]): adds the value of the specified variable to the beginning of the array. If it is a numeric index, the indexes of other elements are correspondingly

Add; if it is an associated array, the index value is not affected.

43. array array_pad (array target_array, int length, mixed pad_value): Fill the array with a specified value.

44. boolean in_array (mixed variable, array target_array [, Boolean strict]): Find whether the array contains the specified element.

45. array array_keys (array target_array [, mixed search_value]): obtains all the indexes in the array.

46. boolean array_key_exists (mixed key, array target_array): checks whether the array contains the specified index.

47. array array_values (array target_array): obtains all element values in the array.

48. Mixed array_search (mixed variable, array target_array [, Boolean strict]): Search for the specified value in the array.

Note: The Return Value of in_array () is boolean. However, if the index is found in array_search (), its index is returned, and only the first matching index value is returned. If the index is not found, false is returned.

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.