2016-06-08 133 views
-2

我有此数组:数组排序多维的关键PHP

Array 
(
    [26] => Array 
    (
     [total_auctions] => 1 
     [total_price] => 0 
    ) 

    [24] => Array 
    (
     [total_auctions] => 0 
     [total_price] => 0 
    ) 

    [25] => Array 
    (
     [total_auctions] => 0 
     [total_price] => 0 
    ) 
) 

我想这个数组排序是:

Array 
(
[24] => Array 
(
    [total_auctions] => 0 
    [total_price] => 0 
) 
[25] => Array 
(
    [total_auctions] => 0 
    [total_price] => 0 
) 

[26] => Array 
(
    [total_auctions] => 1 
    [total_price] => 0 
) 
) 

我试着用array_multisort,但不起作用。你能帮我吗 ? Thx提前。我不明白问题出在哪里,应该正常工作

+0

排序只是'排序()'会做 – Thamilan

+0

没有@Thamilan,它的回报' 1' –

+0

排序不会返回任何值。使用'sort($ arr); print_r($ arr);' – Thamilan

回答

-1

只需使用kso​​rt()对任何数组键

<?php 
$arr = array(
    '26' => array('total_auctions' => 1,'total_price' => 0), 
    '24' => array('total_auctions' => 0,'total_price' => 0), 
    '25' => array('total_auctions' => 0,'total_price' => 0) 
); 
ksort($arr); 
print '<pre>';print_r($arr); 
exit; 
?> 
+0

不工作...这是返回'1' –

+0

是的,但是它改变了键'24,25,26'的地方是'0,1,2' –

+0

使用uasort($ arr,'比较');它将使用用户定义的比较函数对数组进行排序并保持索引关联 –