This article describes how to use the array_multisort function in php to sort two-dimensional arrays. For more information, see. Following the previous article: PHP two-dimensional array sorting custom function, today we will introduce another example of php two-dimensional array sorting. The sorting of two-dimensional arrays in php is very simple. the array_multisort function is mainly used. Example:
67, 'version' => 2); $ data [] = array ('Volume '=> 86, 'version' => 1 ); $ data [] = array ('Volume '=> 85, 'version' => 6); $ data [] = array ('Volume' => 98, 'version' => 2); $ data [] = array ('Volume '=> 86, 'version' => 6 ); $ data [] = array ('Volume '=> 67, 'version' => 7); // get the column list foreach ($ data as $ key => $ row) {$ volume [$ key] = $ row ['Volume ']; $ edition [$ key] = $ row ['version'];} array_multisort ($ volume , SORT_DESC, $ edition, SORT_ASC, $ data); print_r ($ data);?> Output result: Array ([0] => Array ([volume] => 98 [edition] => 2) [1] => Array ([volume] => 86 [edition] => 1) [2] => Array ([volume] => 86 [edition] => 6) [3] => Array ([volume] => 85 [edition] => 6) [4] => Array ([volume] => 67 [edition] => 2) [5] => Array ([volume] => 67 [edition] => 7 )) Note: the parameters of the array_multisort function are very flexible. you can refer to the instructions in the php Manual for in-depth research. >>> For more information, see The php array sorting method < |