Php array common functions, php Array

Source: Internet
Author: User

Php array common functions, php Array

1. Common sorting functions of php arrays.

  • Sort ()-sort arrays in ascending order
  • Rsort ()-Sort arrays in descending order
  • Asort ()-Sort joined arrays in ascending order by value
  • Ksort ()-Sort joined arrays in ascending order by key
  • Arsort ()-Sort associated arrays in descending order by value
  • Krsort ()-Sort associated arrays in descending order by key

2. Common php array Functions

  • Array ()-create an array.
  • Count ()-returns the number of common arrays.
  • In_array (Search,Array,Type)-Whether the specified value exists in the array. (3rd parameters. If this parameter is set to true, check whether the types of search data and array values are the same)
  • Array_map ()-sends each value in the array to the User-Defined Function and returns a new value.
  • Array_pop ()-delete the last element (Out stack) of the array ).
  • Array_push ()-insert one or more elements to the end of the array (inbound stack ).
  • Array_rand ()-returns one or more random keys in the array.
  • Array_unique ()-deletes duplicate values from the array.
  • Array_unshift ()-insert one or more units at the beginning of the array.
  • Array_replace ()-replace the value of the first array ($ a1) with the value of the second array ($ a2.
  • Array_reverse (array, preserve)-The function switches the elements in the original array sequentially, creates a new array, and returns the result. If the second parameter is set to true, the key name of the element remains unchanged; otherwise, the key name is lost.
  • Array_chunk (array, size, preserve_key)-the function bar array is split into a new array.(Size specifies the number of units in each new array. Preserve_key. The default value is fasel. Each result array uses a new array index starting from scratch. true: The key name in the original array is retained)
  • Array_column (array, column_key, index_key)-returns the value of a single column in the input array. (Column_key is required. The column to be returned. It can be an integer index of the Index Array column or a string key value of the column associated with the array. This parameter can also be NULL. In this case, the entire array is returned (useful when the index_key parameter is used to reset the array key ). This function must be used in php5.5 or above)
  • Array_merge ()-the function combines one or more numbers into an array. (Note: 1. If two or more array elements have the same key name, the last element overwrites other elements. 2. If you only input an array to the array_merge () function and the key name is an integer, the function returns a new array with an integer key name, its key name starts from 0 and is re-indexed)
  • Array_combine (key, value)-creates a new array by combining two arrays. One array element is the key name, and the other array element is the key value.
  • Array_count_values ()-This function returns an array. The key name of the element is the value of the original array, and the key value is the number of times this value appears in the original array.
  • Array_key_exists (key, array)-the function checks whether a specified key name exists in an array. If the key name exists, true is returned. If the key name does not exist, false is returned. (Note: If the key name is omitted when you specify an array, an integer key name that starts from 0 and each key value is incremented by 1 is generated .)

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.