PHP array Key-value operations and arrays of statistical functions-functions

Source: Internet
Author: User

1. Array function/function: provides many useful code snippets written by the official, improve the writing speed

1) Array of key-value manipulation functions

Array_values ();//Gets the value in the array

Array_keys ();//Gets the keys in the array

In_array ();//Check if a value is in the array

Array_flip ();//Key and value swap

Array_reverse ();//The values in the array are reversed

Simulation gets the value of key
<?Php$arr=Array ("name"="User1"," Age"=" -","Sex"="nan");foreach($arr as$key =$val) {$keys []=$key; Echo $key."<br>";} Print_r ($keys);?>The result of the operation is Nameagesexarray ([0] = = Name [1] = age [2] = + Sex)

<?php
$arr =array

("Name" = "user1", "age" = "+", "sex" = "Nan");
Print_r (Array_keys ($arr));
?>
When you use a function. Execution results are
Array ([0] = = Name [1] = age [2] = = Sex)
The effect is the same.
In the PHP help document, the brackets indicate that the parameter is optional

2) elements and uniqueness of the statistical array

COUNT ()//number of statistical arrays

array_count_values//the number of duplicate values in the statistics array

array_unique//Remove Duplicates

3) functions for handling arrays using callback functions

Array_filter ()//array value filtering

Array_map ()//function The callback function on the cell of the given array

4) Sorting Functions for arrays

sort//sort the array by value, ascending, not preserving key

rsort//sort the array values by value, descending, not preserving key

asort//sort the array values by value, ascending, preserving the key value

arsort//sort the array values by value, descending, preserving the key value

Ksort ()//key sort

Krsort//key sort

natsort//Natural number Sorting

natcasesort//ignoring case natural number ordering

array_multisort//the sorting of multidimensional arrays

5)

6)

7)

8)

2. String functions

PHP array Key-value operations and arrays of statistical functions-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.