php-Array Operations

Source: Internet
Author: User

Key-value manipulation functions for arrays
("Key Name" = "Key value")
Array_keys ();//Returns all the key names of the array in parentheses
Array_values ()//returns all the key values of the array in parentheses
In_array ("Key value", array);
Search for the key values in that array

Array_key_exists ("Key name", array);
Check if the key name is in that array

Array_flip ();//Swap the key name and value of the array in parentheses
Array_reverse ();//returns an array in reverse order


Elements and uniqueness of a statistical array
Count ();//Returns the number of elements in the array within parentheses
Array_count_values ();//statistics on values in an array
Array_unique ();//delete duplicate values in the array

Functions for working with arrays using callback functions
Array_filter (Array, "callback function");//filter elements in an array with callback functions
Array_map ("function", array);//Use a function to change each value in an array

Reference parameters
Requirements: Array values are added from 1
function Add (& $arr) {
foreach ($arr as $key = = $val) {
$arr [$key]= $val +1;
}
}

Sorting Functions for arrays
Sort ();//ascending does not retain key
Rsort ();//descending does not retain key
Asort ();//L Reserve key
Arsort ();//drop-hold Key
Ksort ();//L key sort
Krsort ();//Descending key sort
Natsort ();//Natural number sort
Natcasesort ();//Ignore case natural number sort
Array_multisort ();//Most Group sort

php-Array Operations

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.