PHP array, the content in the array is roughly as follows:
Copy code 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),
);
For the convenience of expression, I call the three columns of numbers respectively, the three columns of ABC
Requirement: By default, column A is the main sorting method. If column A is the same, the same elements will be sorted in column C in reverse order. Column B does not actually participate in sorting, but it is useful in practical applications, so I also wrote it out.
Method 1:
Copy the code 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 in ascending order, and then install column b in descending order, similar to sql, orderby a asc, b desc
array_multisort($a,SORT_ASC, $c, SORT_DESC, $list);
print_r($ list);
Method 2:
Copy code The code is as follows:
for($j=0 ;$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]);
}
}
http://www.bkjia.com/PHPjc/779000.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/779000.htmlTechArticlePHP array, the contents of the array are roughly as follows: Copy the code 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) , a...