PHP tutorial Array_multisort () function
function bool Array_multisort (array & $arr [, Mixed $arg = Sort_asc [, Mixed $arg = Sort_regular [, mixed $ ...])
Parameter description: function to sort multiple arrays or multidimensional arrays
The first parameter is an array, each subsequent argument may be an array, or it may be the following sort order flag
SORT_ASC-By default, in ascending order
Sort_desc-Sorted in descending order
You can then specify the type of the sort
Sort_regular-Default. Arranges each item in a regular order.
Sort_numeric-Sorts each item in numerical order.
Sort_string-Arranges each item alphabetically.
Instance Code
$arr 1 = Array (' A ', one, one, ten, ' a ');
$arr 2 = Array (1, 2, 3, ' 2 ', 5);
Array_multisort ($arr 1, $arr 2);
The result is:
$arr 1
Array ([0] = [1] = a [2] = = [3] = [4] = 100)
# ' 10 ' in comparison with 11, 100, 100 converts to an integer of 10, less than the other three numbers
# ' 10 ' is in ' a ' comparison as a string, its first character ' 1 ' ASCII value is 49 less than ' a ' (ASCII value is 97), so ' 10 ' is the smallest element
# ' A ' lies in the other three numbers when compared, converted to an integer 0, less than the other three numbers
$arr 2
Array ([0] = 1 [1] = 5 [2] = 2 [3] = 2 [4] = 3)
# $arr 2 element 1 corresponds to the position of the $ARR1 element ' 10 ', so it is at [0] position
# $arr 1[2] +, $arr 1[3] = 100 respectively corresponds to $ARR2 element 3, ' 2 '. 3 is greater than ' 2 ', so the $arr1[2 [corresponding to 2] = 100 is sorted by the subscript
3, with 3 corresponding to the $arr1[3] and 100 ranked subscript 4
Summarize
1. The number of array elements participating in the sorting remains the same
2. The position of the sorted array element is as follows, ' ten ' = 1, one and 2
3. The array in the back is sorted based on the order of the front array
4. The array in front is compared with an array of the same elements.
Grammar
Array_multisort (array1,sorting order,sorting type,array2,array3 ...)
| Parameters |
Description |
| Array1 |
Necessary. Specifies the input array. |
| Sorting order |
Optional. Specify the order of arrangement. The possible values are SORT_ASC and Sort_desc. |
| Sorting type |
Optional. Specifies the sort type. The possible values are Sort_regular, Sort_numeric, and sort_string. |
| Array2 |
Optional. Specifies the input array. |
| Array3 |
Optional. Specifies the input array. |
Hints and Notes
Note: The string key name is retained, but the number key is re-indexed, starting at 0 and incrementing by 1.
Note: You can set the sort order and sort type after each array. If not set, each array parameter uses the default
http://www.bkjia.com/PHPjc/445334.html www.bkjia.com true http://www.bkjia.com/PHPjc/445334.html techarticle PHP Tutorial Array_multisort () function in detail function bool Array_multisort (array $arr [, mixed $arg = Sort_asc [, Mixed $arg = Sort_regular [, mixed $ ...]] ) parameter description: function to more ...