通过密钥php对数组多维度排序

时间:2016-06-08 11:22:47

标签: php php-5.3 php-5.4

我有这个数组:

var query = new Parse.Query('arena');

query.each((arena) => {
  var promise1 = NotificationServices.sendNotification(getPlayerOne(arena));
  var promise2 = NotificationServices.sendNotification(getPlayerTwo(arena));
  return Parse.Promise.when([promise1, promise2])
      .then(() => Parse.Promise.as(), () => Parse.Promise.as()); 
})

我想将此数组排序为:

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 ) ) 但不行。你能帮我吗 ? Thx提前。我不明白问题出在哪里,通常应该有效

1 个答案:

答案 0 :(得分:-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;
?>
相关问题