Php 按两个标准对多维数组排序

Php 按两个标准对多维数组排序,php,arrays,sorting,multidimensional-array,Php,Arrays,Sorting,Multidimensional Array,我有一个具有以下结构的多维数组: $futureInvoices[] = Array( "date" => date("Y-m-d", $ts), "customer" => $possibleDomain->userid, "subtotal" => "0.00", "total" => "0.00", ); 我只想按日期升序和金额降序对数组中的条目进行排序。这怎么可能呢? 多端口阵列 文档中有一个具体的例子 <?php $

我有一个具有以下结构的多维数组:

$futureInvoices[] = Array(
    "date" => date("Y-m-d", $ts),
    "customer" => $possibleDomain->userid,
    "subtotal" => "0.00",
    "total" => "0.00",
);
我只想按日期升序和金额降序对数组中的条目进行排序。这怎么可能呢?

多端口阵列

文档中有一个具体的例子

<?php
$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);
?>
In this example, we will order by volume descending, edition ascending.

We have an array of rows, but array_multisort() requires an array of columns, so we use the below code to obtain the columns, then perform the sorting.

<?php
// Obtain a list of columns
foreach ($data as $key => $row) {
    $volume[$key]  = $row['volume'];
    $edition[$key] = $row['edition'];
}

// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
?>

在本例中,我们将按卷降序、版本升序排序。
我们有一个行数组,但是array_multisort()需要一个列数组,所以我们使用下面的代码获取列,然后执行排序。
在您的例子中,循环将提取date和total的值。然后,对该函数的调用将与使用