PHP array functions (3), php array Functions

Source: Internet
Author: User

PHP array functions (3), php array Functions
Array retrieval functions

    • Format: array array_keys (array arr [, mixed searchValue]); return the "key name" in the arr array in the form of an array. If the optional parameter searchValue is specified, only the key names of the searchValue are returned. Otherwise, all key names in the arr array are returned.
      • NOTE: If searchValue is a string, the time zone is case sensitive.
  1. Array_values () function
    • Format: array array_values (array arr); return all element values in the arr array in the form of arrays (filter out repeated element values ), create a continuous integer "key" for the array ".
  1. In_array () function
    • Format: bool in_array (mixed searchValue, array arr [, bool strict]); check whether the value of searchValue exists in array arr. If yes, TRUE is returned; otherwise, FALSE is returned. If the value of the 3rd strict parameter is TRUE (FALSE by default), The in_array () function also checks whether the data types are the same.
  1. Array_key_exists () function
    • Format: bool array_key_exists (mixed keyName, array arr); check whether the key name keyName exists in array arr. If yes, TRUE is returned; otherwise, FALSE is returned.
  1. Array_search () function
    • Format: mixed array_search (mixed searchValue, array arr [, bool strict]); search for the specified value searchValue in array arr. If it is found, the corresponding key name is returned; otherwise, FALSE is returned. If the value of the 3rd strict parameter is TRUE (FALSE by default), The array_search () function also checks whether the data types are the same.
      • NOTE: If searchValue is a string, the time zone is case sensitive. If searchValue appears more than once in arr, the First Matching key is returned. to return all matching keys, use the array_keys () function.
  1. Array_unique () function
    • Format: array array_unique (array arr); returns a new array that removes the repeated element "value" from the array arr.
      • Note: The array_unique () function maintains the original "key-Value Pair" correspondence, and only keeps the first key name for each value.
Array sorting Function
    • Format: bool sort (array & arr); sort () function sorts the array arr in ascending order of the element "value. (If sorting is successful, TRUE is returned; otherwise, FALSE is returned)
      • Note: The sort () function assigns a new "integer" key name to the sorted array arr.
  1. Asort () function
    • Format: bool asort (array & arr); The asort () function sorts the array arr in ascending order of the element "value. (If sorting is successful, TRUE is returned; otherwise, FALSE is returned)
      • Note: After the array arr is sorted by the asort () function, the original "key-value pairs" of the array elements are maintained.
  1. Rsort () and arsort () functions <sort in descending order>
    • The syntax format of rsort () and sort () functions is the same;
    • The syntax format of arsort () and asort () functions is the same;
    • The difference is that the rsort () function and the arsort () function sort the array in descending order.
  1. Ksort () function
    • Format: bool ksort (array & arr); sort the array arr in ascending order of key names, and maintain the original "key-value pairs" of array elements. (If the call succeeds, TRUE is returned; otherwise, FALSE is returned)
  1. Krsort () function
    • Format: The krsort () function sorts the array arr in descending order by key name, and maintains the correspondence between the original "key-value pairs" of the array elements. (If the call succeeds, TRUE is returned; otherwise, FALSE is returned)
  1. Natsort () function
    • Format: bool natsort (array & arr); use the "natural sorting" algorithm to sort the "values" of array arr elements in ascending order (case sensitive ), and keep the original "key-value pairs" of array elements unchanged.
  1. Natcasesort () function
    • Format: bool natcasesort (array & arr); use the "natural sorting" algorithm to sort the "values" of array arr elements in ascending order of uppercase/lowercase letters, and keep the original "key-value pairs" of array elements unchanged.
  1. Shuffle () function
    • Format: bool shuffle (array & arr); random sort for array arr, and assign a new key name to the random sort array arr.
  1. Array_reverse () function
    • Format: array array_reverse (array arr [, bool preserve_keys]); returns a new array in the opposite order of array arr elements, if the value of preserve_keys is TRUE, the original "key-value pairs" of the array elements remain unchanged.
Sort Function Memory skills: // "a" indicates association, meaning that the ing relationship of "key-value pairs" remains unchanged during sorting; sort "k" indicates key, the meaning is to sort by the array element "key" rather than the array element "value"; reverse "r" indicates reverse, meaning to sort by the descend of the array element "value; "nat" indicates natural, meaning that the "value" of the array element is sorted by the "natural sorting" algorithm.

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.