PHP Code:
$data['Ledgers'] = array_merge($data['Invoices'],$data['Payments']);
usort($data['Ledgers'], function( $a, $b ) {return strtotime($a["Create_date"]) - strtotime($b["Create_date"]);});
Output:
[Ledgers] => Array
(
[0] => Array
(
[Title] => Cash
[Create_date] => 2017-09-14
[Amount] => 12000
[Type] => Credit
)
[1] => Array
(
[Title] => 24
[Create_date] => 2017-09-14
[Amount] => 12600
[Type] => Debit
)
[2] => Array
(
[Title] => 25
[Create_date] => 2017-09-14
[Amount] => 1000
[Type] => Debit
)
)
[Payments] => Array
(
[0] => Array
(
[Title] => Cash
[Create_date] => 2017-09-14
[Amount] => 12000
[Type] => Credit
)
)
[Invoices] => Array
(
[0] => Array
(
[Title] => 24
[Create_date] => 2017-09-14
[Amount] => 12600
[Type] => Debit
)
)
Expected Output:
[Ledgers] => Array
(
[0] => Array
(
[Title] => 24
[Create_date] => 2017-09-14
[Amount] => 12600
[Type] => Debit
)
[1] => Array
(
[Title] => 25
[Create_date] => 2017-09-14
[Amount] => 1000
[Type] => Debit
)
[2] => Array
(
[Title] => Cash
[Create_date] => 2017-09-14
[Amount] => 12000
[Type] => Credit
)
)
Anyone can help me How can I sort two keys 1st is Create_date = ASC and 2nd is Type = DESC? sorry for my weak English. please try to improve readability of this question if you can. your help is appreciated.
Someone requested for Payments and Invoices. I posted both arrays. now please help me.