PHP array functions

Source: Internet
Author: User
Tags array sort

Array (..) List (...) Range ($low, $high, $step)
Array_combine ($key _arr, $value _arr)Key+valuearray_merge ($arr 1, $arr 2..) Merge array same index append same key name overwrite array_merge_recursive ($arr 1, $arr 2 ...)Recursively merging arrays without overwriting the compact ("VarName" ...) Array extract ($arr) with the value of the variable To restore an array to multiple variables
Array_chunk ($arr, $size, False|true)Split array does not retain key| reserved Keyarray_count_values ($arr) Count the occurrences of each element
Array_fill ($start, $size, $value)Fill array array_pad ($arr, $size, $value) Fills an array to a specified length
Shuffle ($arr) Scrambled array Array_reverse ($arr) Flip Array array_flip ($arr) Swap the keys and values of an array
Array_rand ($arr, size) Randomly extracts a size element from an array array_slice ($arr, $offset, $length)Take an element of an array array_splice ($arr, $offset, $length, $replace)Replace/delete an element in an array array_unique ($arr) Move duplicate values in an array
Count ($arr) Number of elements ==sizeof ($arr)? Array_product ($arr) The product array_sum of an array ($arr) Array of and-------------------------------------------------------------------------------//subtraction and intersection Array_diff ($arr 1,$ Arr2..) Array difference set Array_udiff ($arr 1, $arr 2 ...) Use the callback function to compare the data to calculate the difference set of the array. ARRAY_DIFF_ASSOC ($arr 1, $arr 2..)Using the index to get the difference set ARRAY_UDIFF_ASSOC ($arr 1, $arr 2 ...)The index check calculates the difference set of the array and compares the data with the callback function. ARRAY_DIFF_UASSOC ($arr 1, $arr 2 ..., "Fun_name")The index is ARRAY_UDIFF_UASSOC with a callback function ($arr 1, $arr 2: "Fun_name")The index check calculates the difference set of the array, using the callback function to compare the data and the index. Array_diff_key ($arr 1, $arr 2..)Using the key name to get the difference set Array_diff_ukey ($arr 1, $arr 2, "Fun_name")Use the callback function to get the difference between the key names Array_intersect ($arr 1, $arr 2).Computes the intersection of an array. Array_uintersect ($arr 1, $arr 2..)Computes the intersection of an array and compares the data with a callback function. ARRAY_INTERSECT_ASSOC ($arr 1, $arr 2..)Compares the key name and the key value, and returns an array of two arrays of intersections. ARRAY_UINTERSECT_ASSOC ($arr 1, $arr 2..)With the index check to compute the intersection of the array, compare the data with the callback function. ARRAY_INTERSECT_UASSOC ($arr 1, $arr 2:, "Fun_name")//Index Check the intersection of the computed array, and use the callback function to compare the indexes. ARRAY_UINTERSECT_UASSOC ($arr 1, $arr 2:, "Fun_name")//with index check the intersection of the computed array, use the callback function to compare the data and index Array_intersect_key ($arr 1, $arr 2 ...)Computes the intersection of an array using the key name comparison. Array_intersect_ukey ($arr 1, $arr 2 ..., "Fun_name")Use the callback function to compare the key names to calculate the intersection of the arrays. -------------------------------------------------------------------------------//Elements Enter/Remove Array_push ($arr, ele ...) Array_pop ($arr) array_unshift ($arr, ele ...) Array_shift ($arr)-------------------------------------------------------------------------------//Custom Function Array_ Reduce ($arr, "Fun_name")Each element in a recursive array is given a value such as array_filter, product, etc. ($arr, "Fun_name")Using callback functions to filter array array_map ("Fun_name", $arr) Call function Array_walk ($arr, ' fun_name ') for each element Use the user function array_walk_recursive ($arr, ' fun_name ') for each memberRecursively use the user function for each member-------------------------------------------------------------------------------//pointer current ($arr ) Current value ==pos ($arr)? Next ($arr) Pointer move back prev ($arr) Pointer move forward end ($arr) The pointer moves to the last reset ($arr) The pointer moves to the first each ($arr) Returns the current Key-value pointer moves back-------------------------------------------------------------------------------//key and value Array_ Key_exists ($key, $arr) Whether the key name exists In_array ($value, $arr) Whether the value exists Array_search ($value, $arr) Returns the key name of the element key ($arr) The key name of the current value array_change_key_case ($arr, case_lower| Case_upper)Change the key name to small/uppercase Array_keys ($arr) Key an array group array_values ($arr) Array of values-------------------------------------------------------------------------------//Sort Array_multisort ($arr 1, $arr 2..)Sort multiple arrays or multidimensional arrays (SORT_ASC sort_desc sort_regular sort_numeric sort_string) sort ($arr) Array sort Rsort ($arr) Array inverse sort Natsort ($arr) Natural sort Natcasesort ($arr) Array is case-insensitive natural sort asort ($arr) Value sort Arsort ($arr) Value Reverse sort ksort ($arr) Key sort Krsort ($arr) Key reverse Sort usort ($arr) Custom array sort Uasort ($arr) Custom values Sort Uksort ($arr) Custom Key Sorting-------------------------------------------------------------------------------

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.