PHP Array Common functions

Source: Internet
Author: User

1,php An array of commonly used sorting functions.
    • Sort ()-sorts an array in ascending order
    • Rsort ()-sorts the array in descending order
    • Asort ()-sorts associative arrays in ascending order based on values
    • Ksort ()-Sorts the associative array in ascending order, based on the key
    • Arsort ()-sorts associative arrays in descending order by value
    • Krsort ()-Sorts the associative array in descending order, based on the key
2,php commonly used array functions
  • Array ()-creates the arrays.
  • COUNT ()-Returns the number of commonly used in the array.
  • In_array (Search,array,type)-whether the specified value exists in the array. (the 3rd parameter, if set to true, checks whether the data being searched is the same as the type of the array's value)
  • Array_map ()-sends each value in the array to the user-defined function, returning the new value.
  • Array_pop ()-Deletes the last element of the array (out of the stack).
  • Array_push ()-inserts one or more elements into the end of the array (into the stack).
  • Array_rand ()-returns one or more random keys in the array.
  • Array_unique ()-Deletes duplicate values in the array.
  • Array_unshift ()-inserts one or more cells at the beginning of the array.
  • Array_replace ()-Replaces the value of the first array ($a 1) with the value of the second array ($a 2).
  • Array_reverse (Array,preserve)-The function flips the order of elements in the original array, creates a new array, and returns. If the second parameter is specified as true, the key name of the element remains unchanged, otherwise the key will be lost
  • Array_chunk (Array,size,preserve_key)-function bar array is split into a new array. (size specifies how many cells are included in each new array.) Preserve_key, optional default is Fasel, each result array uses a new zero-based array index; True: Retains key names from the original array)
  • Array_column (Array,column_key,index_key)-Returns the value of a single column in the input array. (Column_key required.) A column that requires a return value. Can be an integer index of the column of an indexed array, or a string key value for a column of an associative array. This parameter can also be null, which is useful when the entire array is returned (with the Index_key parameter to reset the array key). The function must be used above php5.5)
  • Array_merge ()-the function merges one or more arrays into an array. (Note: 1. If two or more array elements have the same key name, the last element overrides the other element.) 2. If you enter an array only to the Array_merge () function, and the key name is an integer, the function returns a new array with an integer key name, whose key name is re-indexed starting at 0)
  • Array_combine (Key,value)-Creates a new array by merging two arrays, where one array element is the key name and the other array element is the key value.
  • Array_count_values ()-This function returns an array whose key name is the value of the original array, and the key value is the number of occurrences of the value in the original array
  • Array_key_exists (Key,array)-The function checks whether a specified key name exists in an array, returns true if the key name exists, or False if the key name does not exist. (Note: If you omit the key name when you specify an array, an integer key name that starts at 0 and corresponds to 1 increments for each key value) is generated. )

PHP Array Common functions

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.