An array of PHP, in which the contents of the array are roughly as follows:
. The code is as follows:
$list = Array (
Array (2,3,5),
Array (2,5,24),
Array (3,8,6),
Array (3,2,10),
Array (4,7,20),
Array (4,1,15),
Array (6,4,10),
Array (7,9,20),
);
to make it easier to express, I'm calling the 3-column number, the three-column ABC
Requirements: The default is sorted by column A, and if column A is the same, the same elements are arranged in reverse order in column C. Column B actually didn't participate in the sort, but it was useful in practical use, so I wrote it.
Method One:
. The code is as follows:
$a = $c = Array ();
foreach ($list as $val) {
$a [] = $val [0]; Column A
$c [] = $val [2]; Column C
}
Install column A ascending, then install column B descending, similar to Sql,orderby a asc,b desc
array_multisort ($a, SORT_ASC, $c, Sort_desc, $list);
Print_r ($list);
Method Two:
. The code is as follows:
for ($j =0; $j <count ($list); $j + +) {
for ($i =count ($list)-1; $i > $j; $i-) {
if ($list [$i][0] = = $list [$i -1][0] && $list [$i][2] > $list [$i -1][2])
list ($list [$i], $list [$i-1]) = Array ($list [$i-1], $list [$i]);
}
}