Php 多数组排序
我的数组是这样的Php 多数组排序,php,arrays,sorting,multidimensional-array,Php,Arrays,Sorting,Multidimensional Array,我的数组是这样的 Array ( [0] => Array ( [salesID] => 7 [creditID] => 9 [amount] => 80400.00 [due_date] => 2018-12-12 [status] => no [given_date] => 2018-09-30 [av_class] => table
Array (
[0] => Array (
[salesID] => 7
[creditID] => 9
[amount] => 80400.00
[due_date] => 2018-12-12
[status] => no
[given_date] => 2018-09-30
[av_class] => table-warning
[name] => Kumaari
[contact] => 0
)
[1] => Array (
[salesID] => 3
[creditID] => 8
[amount] => 500.00
[due_date] => 2019-06-25
[status] => yes
[given_date] => 2018-09-30
[av_class] => table-success
[name] => Zayan
[contact] => 0765894520
)
)
我想按子数组的值缩短/重新订购主数组:[到期日]
请帮帮我。主数组键不是必需的,但子数组键无法更改 您需要这样编写代码
<?php
$inventory = array(
array(
"salesID"=>7,
"creditID"=>9,
'amount'=>80400.00,
'due_date'=>strtotime(2018-12-12),
'status' => 'no',
'given_date' => 'no',
'av_class' => 'no',
'name' => 'no',
'contact' => 0
),
array(
"salesID"=>3,
"creditID"=>8,
'amount'=>500.00,
'due_date'=>strtotime(2019-06-25),
'status' => 'yes',
'given_date' => '2018-09-30',
'av_class' => 'table-success',
'name' => 'Zayan',
'contact' => '0765894520'
)
);
$date = array();
foreach ($inventory as $key => $row)
{
$date[$key] = $row['due_date'];
}
array_multisort($date, SORT_DESC, $inventory);
echo '<pre>';
print_r($inventory);
?>
这将根据到期日期按降序对数组进行排序。但是您需要在数组中使用带有日期的“strotime()”函数。事实是:因为您的可比较日期是
Y-m-d
,所以您可以简单地将它们作为字符串(而不是日期)进行比较。在问这个问题之前,你需要研究和尝试一些东西。我可以知道为什么要投反对票吗?