PHP array knowledge sorting, php array sorting

Source: Internet
Author: User

PHP array knowledge sorting, php array sorting

Array: the language structure composed of key-value pairs,

Dimension can be divided into one-dimensional array and multi-dimensional array.

Keys can be divided into index arrays and associated arrays.

--------------------- PHP array ---------------------------

How to create an array:

$ Ar_1 = array (); // empty array

$ Ar_2 = array (, 2) // Initialize an array with three values

$ Ar_3 [0] = 1; $ ar_3 ['name'] = "YOU"; $ ar_3 [] = 1; // This is also the method for creating arrays.

Multi-dimensional array: the key of the one-dimensional array is another Array

$ Ar = array (

'Ar _ 1' = array (),

'Ar _ 2' = array ()

)

--- Array Method

Count (); // returns the length of the array. The index of the array starts from 0.

Sort ()-sort arrays in ascending order

Rsort ()-Sort arrays in descending order

Asort ()-sort the array in ascending order based on the value of the associated array

Ksort ()-sort the array in ascending order based on the keys of the associated array

Arsort ()-Sort arrays in descending order based on the values of associated Arrays

Krsort ()-sort the array in descending order based on the keys of the associated array

--- Traverse the Array

Foreach ($ ar as $ values); // get value

Foreach ($ ar as $ keys => $ values) // obtain the key and value values.

For ($ I = 0; $ I <count ($ ar); I ++); // You can also

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.