PHP array functions (3)

Source: Internet
Author: User
Tags array sort shuffle sorts

Array Retrieval function
    1. Array_keys () function
      • Format: Array array_keys (array arr[, mixed searchvalue]), returns the "key Name" in the ARR array as an array, and if an optional argument searchvalue is specified, returns only the key name of the Searchvalue value. Otherwise all key names in the ARR array will be returned.
        • Note: If Searchvalue is a string, the comparison is case-sensitive.
    1. Array_values () function
      • Format: Array array_values (array arr), returns all the element values in the ARR array as arrays (filters out duplicate element values), and establishes a contiguous integer "key" for the array.
    1. In_array () function
      • Format: BOOL In_array (mixed Searchvalue,array arr [, BOOL strict]); checks if the array exists in ARR for a value of searchvalue, there is a return of true, otherwise false is returned. If the value of the 3rd parameter Strict is true (the default is False), the In_array () function also checks whether the data type is the same.
    1. Array_key_exists () function
      • Format: BOOL Array_key_exists (mixed Keyname,array arr); checks if the array exists in ARR for a key name KeyName, there is a return of true, otherwise false is returned.
    1. Array_search () function
      • Format: Mixed array_search (mixed Searchvalue,array arr[,bool strict]); Searches for the given value Searchvalue in the array arr, returns the corresponding key name if found, otherwise returns false. If the value of the 3rd parameter Strict is true (the default is False), the Array_search () function also checks whether the data type is the same.
        • Note: If Searchvalue is a string, the comparison is case-sensitive, and if searchvalue occurs more than once in Arr, the first matching key is returned, and the key to return all matching values should be used with the Array_keys () function.
    1. Array_unique () function
      • Format: Array array_unique (array arr); Returns a new array that removes the repeating element "value" in arr.
        • Note: the Array_unique () function retains the original "key-value pair" correspondence, preserving only the first key name encountered for each value.
Array sort function
    1. Sort () function
      • Format: bool Sort (array &arr); the sort () function sorts an array of arr by the ascending element "value". (The sort succeeds returns True, otherwise returns false)
        • Description: 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 an array of arr in ascending order of the element "value". (The sort succeeds returns True, otherwise returns false)
        • Description: After the array arr is sorted by the Asort () function, the original "key-value pair" Correspondence of the array element is maintained.
    1. Rsort () function and Arsort () function < descending arrangement >
      • The Rsort () function has the same syntax format as the sort () function;
      • The Arsort () function has the same syntax format as the Asort () function;
      • The difference is that the Rsort () function and the Arsort () function are arranged in descending order of an array.
    1. Ksort () function
      • Format: bool Ksort (array &arr), an array of arr in ascending order of key names, and preserving the original "key-value pairs" correspondence of the elements of the arrays. (Returns true successfully, otherwise false)
    1. Krsort () function
      • Format: Krsort () function array arr is arranged in descending order of key names and preserves the original "key-value pair" Correspondence of the array elements. (Returns true successfully, otherwise false)
    1. Natsort () function
      • Format: bool Natsort (array &arr), the "natural sort" algorithm is used to sort the arr element "value" in ascending order (case-sensitive), and the corresponding relationship of the original "key-value pair" of the array element remains unchanged.
    1. Natcasesort () function
      • Format: bool Natcasesort (array &arr), and the "natural sort" algorithm for the "value" of the arr element is an ascending sort of case-insensitive letter, keeping the original "key-value pair" Correspondence of the array element unchanged.
    1. Shuffle () function
      • Format: BOOL Shuffle (array &arr), an array of arr is randomly ordered, and a new key name is assigned to arr after a random sort.
    1. Array_reverse () function
      • Format: Array array_reverse (array arr[,bool preserve_keys]); Returns a new array with the opposite order of the ARR elements, preserving the original "key-value pair" of the array element if Preserve_keys is True The corresponding relationship is unchanged.
sorting function Memory Skills:/"a" denotes association, meaning that the corresponding relationship of "key value pair" is maintained in the process of sorting; ▏ "K" in the sorting function denotes key, meaning that it is sorted by the array element "key" rather than the array element "value"; ╲ "R" means reverse, meaning that it is sorted by descending (descend) of the array element "value", and "Nat" means natural, meaning that the "natural sort" algorithm is used to sort the "value" of the group element.

PHP array functions (3)

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.