Home > Backend Development > PHP Tutorial > php数组排序问题

php数组排序问题

WBOY
Release: 2016-06-23 13:08:28
Original
1045 people have browsed it

刚刚接触php三天,以前的编程经验zero,所以这真的是一个小白问题。我已经上网检索了,没有查到解决办法T_T,
有点着急,特来求助。
假设现在我有这样一个数组:
$a[0][0]="3499230933";
$a[0][1]=9.25;
$a[1][0]="4499230933";
$a[1][1]=9.25;
$a[2][0]="2499230933";
$a[2][1]=10;
$a[3][0]="1499230933";
$a[3][1]=9.70;
$a[4][0]="6499230933";
$a[4][1]=9.45;
$a[5][0]="5499230933";
$a[5][1]=9.27;
我想让它按照$[][1]的值排序,期待的排序结果如下:
$a[2][0]="2499230933";
$a[2][1]=10;
$a[3][0]="1499230933";
$a[3][1]=9.70;
$a[4][0]="6499230933";
$a[4][1]=9.45;
$a[5][0]="5499230933";
$a[5][1]=9.27;
$a[0][0]="3499230933";
$a[0][1]=9.25;
$a[1][0]="4499230933";
$a[1][1]=9.25;


回复讨论(解决方案)

$a[0][0]="3499230933";$a[0][1]=9.25;$a[1][0]="4499230933";$a[1][1]=9.25;$a[2][0]="2499230933";$a[2][1]=10;$a[3][0]="1499230933";$a[3][1]=9.70;$a[4][0]="6499230933";$a[4][1]=9.45;$a[5][0]="5499230933";$a[5][1]=9.27;foreach($a as $v) $r[] = $v[1];array_multisort($r, SORT_DESC, $a);print_r($a);
Copy after login
Array(    [0] => Array        (            [0] => 2499230933            [1] => 10        )    [1] => Array        (            [0] => 1499230933            [1] => 9.7        )    [2] => Array        (            [0] => 6499230933            [1] => 9.45        )    [3] => Array        (            [0] => 5499230933            [1] => 9.27        )    [4] => Array        (            [0] => 3499230933            [1] => 9.25        )    [5] => Array        (            [0] => 4499230933            [1] => 9.25        ))
Copy after login

谢谢你,超感动的,真的很感谢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template