【发布时间】:2018-10-19 17:07:23
【问题描述】:
数组:
Array
(
[0] => Array
(
[Create_date] => 2017-10-17
[Description] => Cash
[Debit] =>
[Credit] => 27612
[Type] => Credit
)
[1] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 22
[Debit] => 27612
[Credit] =>
[Type] => Debit
)
[2] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 20
[Debit] => 1008
[Credit] =>
[Type] => Debit
)
[3] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 19
[Debit] => 1168.2
[Credit] =>
[Type] => Debit
)
[4] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 18
[Debit] => 276.12
[Credit] =>
[Type] => Debit
)
)
PHP:
function date_compare($a, $b)
{
$t1 = strtotime($a['Create_date']);
$t2 = strtotime($b['Create_date']);
return $t1 - $t2;
}
usort($data['Ledgers'], 'date_compare');
预期输出:
[0] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 22
[Debit] => 27612
[Credit] =>
[Type] => Debit
)
[1] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 20
[Debit] => 1008
[Credit] =>
[Type] => Debit
)
[2] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 19
[Debit] => 1168.2
[Credit] =>
[Type] => Debit
)
[3] => Array
(
[Create_date] => 2017-10-17
[Description] => Invoice ID = 18
[Debit] => 276.12
[Credit] =>
[Type] => Debit
)
[4] => Array
(
[Create_date] => 2017-10-17
[Description] => Cash
[Debit] =>
[Credit] => 27612
[Type] => Credit
)
执行函数后,我得到了这个数组。现在我想按日期和字符排序数组。我给出了我的预期输出任何人都可以请帮助我我怎样才能达到我的预期输出?对不起我的语法错误。请编辑此问题以提高可读性,以便对其他人有所帮助。
【问题讨论】:
-
这些数组是否来自数据库?`如果是,为什么不对查询进行排序?
-
所以你想 order_by date 和 char ?你是什么意思字符?哪个角色?
-
检查我的预期输出后检查你是否能理解我想要什么。 对试图帮助你的人来说不是很好/建设性的评论。。这里的人都是志愿者
-
字符...???
-
哪个角色...@shahrushabh