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