- $data [] = Array (' volume ' = +, ' edition ' = 2);
- $data [] = Array (' volume ' = +, ' edition ' = 1);
- $data [] = Array (' volume ' = =, ' edition ' = 6);
- $data [] = Array (' volume ' = = 98, ' edition ' = 2);
- $data [] = Array (' volume ' = +, ' edition ' = 6);
- $data [] = Array (' volume ' = +, ' edition ' = 7);
- ?>
Copy CodeExample 2:
- $a = Array (+/-);
- $b = Array (3);
- Sort data in descending order according to volume, in ascending order of edition
- The $data as the last parameter, sorted by the Universal key
- Array_multisort ($a, $b, $data);//array one-dimensional number is different
- Var_dump ($data);
- ?>
Copy CodeThe above test code indicates the number of inconsistencies in the array. Warning:array_multisort (): Array sizes is inconsistent in G:\www\test\index.php on LINE15 Let's look at an example:
- $data [] = Array (' volume ' = +, ' edition ' = 2);
- $data [] = Array (' volume ' = +, ' edition ' = 1);
- $data [] = Array (' volume ' = =, ' edition ' = 6);
- $data [] = Array (' volume ' = = 98, ' edition ' = 2);
- $data [] = Array (' volume ' = +, ' edition ' = 6);
- $data [] = Array (' volume ' = +, ' Edition ' = 7, 3, +);//Two-dimensional number is different
- ?>
Copy CodeCode Listing 2:
- $a = array (11,2,3,4,5,6);
- $b = Array (3,3,3,3,3,3);
- From the results, we see that the corresponding 11 array (67,7,3,4,4) appears in the same order;
- Sort data in descending order according to volume, in ascending order of edition
- The $data as the last parameter, sorted by the Universal key
- Array_multisort ($a, $b, $data);
- Var_dump ($a, $data);
- ?>
Copy CodeAs you can tell from the above results, the array parameter must have the same number of one-dimensional, and then the corresponding position of each array (note not the same key, but from the natural position, such as $ A (1=>4), corresponding to the $b (99=>4) 4, because their position is the first, not a key ( 1,99), the corresponding position of the value is like wearing on each other equal to the bamboo pole, wearing one of the above values need to adjust the position, it will cause the same "bamboo bar" on the other values appear vertical movement. Class: $a $b $c 4=>7 8=>10 ' 999 ' = 09=>9 0=>1 999=>90=> 2 9=> 3 9999=>7If there is a $ A 7 and 9 swap, it will drive the $b 10 and 1 of the swap $c 0 and 9. So the relationship is like the above three arrays, the same color on the same "front", one of them, we have to change positions together. Let's introduce these and hopefully help you understand the use of multisort array sorting. >>> For more information, check out the PHP array sorting method Daquan <<< |