Home > php教程 > php手册 > 请教数组如何多条件排序

请教数组如何多条件排序

WBOY
Release: 2016-06-06 19:41:30
Original
1272 people have browsed it

请问数组怎么多条件排序 array( '000-00'=array( 'qty'=20, 'price'=200 ), '0001-00'=array( 'qty'=10, 'price'=100 ), '0002-00'=array( 'qty'=30, 【本文来自鸿网互联 (http://www.68idc.cn)】'price'=50 ) ) 请问怎么样先按qty由小到大排序,然后按Price

请问数组怎么多条件排序
array(
       '000-00'=>array(
                                    'qty'=>20,
                                    'price'=>200
                                  ),
       '0001-00'=>array(
                                     'qty'=>10,
                                    'price'=>100
                                  ),
      '0002-00'=>array(
                                      'qty'=>30,
                               【本文来自鸿网互联 (http://www.68idc.cn)】      'price'=>50
                                 )

 )

请问怎么样先按qty由小到大排序,然后按Price由大到小排序。


------解决思路----------------------
$a = array(<br />
       '000-00'=>array(<br />
                                    'qty'=>20,<br />
                                    'price'=>200<br />
                                  ),<br />
       '0001-00'=>array(<br />
                                     'qty'=>10,<br />
                                    'price'=>100<br />
                                  ),<br />
      '0002-00'=>array(<br />
                                      'qty'=>30,<br />
                                     'price'=>50<br />
                                 )<br />
<br />
 );<br />
foreach($a as $k=>$v) {<br />
  $qty[] = $v['qty'];<br />
  $price[] = $v['price'];<br />
}<br />
array_multisort($qty, $price, SORT_DESC, $a);<br />
print_r($a);
Copy after login
Array<br />
(<br />
    [0001-00] => Array<br />
        (<br />
            [qty] => 10<br />
            [price] => 100<br />
        )<br />
<br />
    [000-00] => Array<br />
        (<br />
            [qty] => 20<br />
            [price] => 200<br />
        )<br />
<br />
    [0002-00] => Array<br />
        (<br />
            [qty] => 30<br />
            [price] => 50<br />
        )<br />
<br />
)<br />
<br />
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template