How to PHP USORT based on date and time?
There is PHP array which I want to sort it date and time wise but things not working as expected. How can I sort this array according to incrementing date and time wise?
Original Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[5] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[6] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[7] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[8] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[9] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[13] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[15] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[17] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[18] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[21] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
[24] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[25] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[26] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
)
USORT Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[5] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[6] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[7] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[8] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[9] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[13] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[15] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[17] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[18] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[21] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[24] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[25] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
[26] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
)
PHP Code:
Sorted Time wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_time"]) - strtotime($b["Create_time"]);});
Sorted Date wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_date"]) - strtotime($b["Create_date"]);});
php
add a comment |
There is PHP array which I want to sort it date and time wise but things not working as expected. How can I sort this array according to incrementing date and time wise?
Original Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[5] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[6] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[7] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[8] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[9] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[13] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[15] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[17] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[18] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[21] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
[24] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[25] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[26] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
)
USORT Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[5] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[6] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[7] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[8] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[9] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[13] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[15] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[17] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[18] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[21] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[24] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[25] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
[26] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
)
PHP Code:
Sorted Time wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_time"]) - strtotime($b["Create_time"]);});
Sorted Date wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_date"]) - strtotime($b["Create_date"]);});
php
add a comment |
There is PHP array which I want to sort it date and time wise but things not working as expected. How can I sort this array according to incrementing date and time wise?
Original Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[5] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[6] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[7] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[8] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[9] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[13] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[15] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[17] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[18] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[21] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
[24] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[25] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[26] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
)
USORT Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[5] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[6] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[7] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[8] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[9] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[13] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[15] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[17] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[18] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[21] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[24] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[25] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
[26] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
)
PHP Code:
Sorted Time wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_time"]) - strtotime($b["Create_time"]);});
Sorted Date wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_date"]) - strtotime($b["Create_date"]);});
php
There is PHP array which I want to sort it date and time wise but things not working as expected. How can I sort this array according to incrementing date and time wise?
Original Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[5] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[6] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[7] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[8] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[9] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[13] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[15] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[17] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[18] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[21] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
[24] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[25] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[26] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
)
USORT Array:
Array
(
[0] => Array
(
[ID] => 44
[Create_date] => 2018-07-07
[Create_time] => 19:00:56
[Invoice_series] => RR
[Invoice_id] => 9
[Amount] => 9402
[Type] => Debit
[Method] => Sale
)
[1] => Array
(
[ID] => 46
[Create_date] => 2018-07-09
[Create_time] => 16:13:36
[Invoice_series] => RR
[Invoice_id] => 10
[Amount] => 598
[Type] => Debit
[Method] => Sale
)
[2] => Array
(
[ID] => 47
[Create_date] => 2018-07-10
[Create_time] => 16:52:22
[Invoice_series] => VS
[Invoice_id] => 5
[Amount] => 10000
[Type] => Debit
[Method] => Sale
)
[3] => Array
(
[ID] => 48
[Create_date] => 2018-07-10
[Create_time] => 16:59:32
[Invoice_series] => VS
[Invoice_id] => 6
[Amount] => 16757
[Type] => Debit
[Method] => Sale
)
[4] => Array
(
[ID] => 9
[Create_date] => 2018-07-28
[Create_time] => 15:10:33
[Invoice_series] => SRT
[Invoice_id] => 1
[Amount] => 1237
[Type] => Credit
[Method] => sale_return
)
[5] => Array
(
[ID] => 10
[Create_date] => 2018-09-17
[Create_time] => 15:43:30
[Invoice_series] => SRT
[Invoice_id] => 2
[Amount] => 361
[Type] => Credit
[Method] => sale_return
)
[6] => Array
(
[ID] => 14
[Create_date] => 2018-09-18
[Create_time] => 10:06:52
[Invoice_series] => SRT
[Invoice_id] => 4
[Amount] => 6262
[Type] => Credit
[Method] => sale_return
)
[7] => Array
(
[ID] => 13
[Create_date] => 2018-09-18
[Create_time] => 10:04:38
[Invoice_series] => SRT
[Invoice_id] => 3
[Amount] => 4307
[Type] => Credit
[Method] => sale_return
)
[8] => Array
(
[ID] => 15
[Create_date] => 2018-09-29
[Create_time] => 17:02:39
[Invoice_series] => SRT
[Invoice_id] => 5
[Amount] => 2253
[Type] => Credit
[Method] => sale_return
)
[9] => Array
(
[ID] => 76
[Create_date] => 2018-10-01
[Create_time] => 11:44:20
[Invoice_series] => VS
[Invoice_id] => 14
[Amount] => 1799
[Type] => Debit
[Method] => Sale
)
[10] => Array
(
[ID] => 78
[Create_date] => 2018-10-01
[Create_time] => 18:44:08
[Invoice_series] => VS
[Invoice_id] => 16
[Amount] => 19656
[Type] => Debit
[Method] => Sale
)
[11] => Array
(
[ID] => 77
[Create_date] => 2018-10-01
[Create_time] => 18:41:00
[Invoice_series] => VS
[Invoice_id] => 15
[Amount] => 1213
[Type] => Debit
[Method] => Sale
)
[12] => Array
(
[ID] => 89
[Create_date] => 2018-10-04
[Create_time] => 10:02:50
[Invoice_series] => VS
[Invoice_id] => 17
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[13] => Array
(
[ID] => 18
[Create_date] => 2018-10-12
[Create_time] => 11:14:34
[Invoice_series] => SRT
[Invoice_id] => 6
[Amount] => 3186
[Type] => Credit
[Method] => sale_return
)
[14] => Array
(
[ID] => 94
[Create_date] => 2018-10-22
[Create_time] => 14:58:22
[Invoice_series] => VS
[Invoice_id] => 21
[Amount] => 9251
[Type] => Debit
[Method] => Sale
)
[15] => Array
(
[ID] => 29
[Create_date] => 2018-10-24
[Create_time] => 19:44:03
[Invoice_series] => SRT
[Invoice_id] => 7
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[16] => Array
(
[ID] => 97
[Create_date] => 2018-10-24
[Create_time] => 11:47:51
[Invoice_series] => VS
[Invoice_id] => 22
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[17] => Array
(
[ID] => 98
[Create_date] => 2018-10-24
[Create_time] => 15:02:05
[Invoice_series] => VS
[Invoice_id] => 23
[Amount] => 5000
[Type] => Debit
[Method] => Sale
)
[18] => Array
(
[ID] => 30
[Create_date] => 2018-10-25
[Create_time] => 16:52:29
[Invoice_series] => SRT
[Invoice_id] => 8
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[19] => Array
(
[ID] => 51
[Create_date] => 2018-10-26
[Create_time] => 15:25:36
[Invoice_series] => SRT
[Invoice_id] => 10
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[20] => Array
(
[ID] => 109
[Create_date] => 2018-10-26
[Create_time] => 18:26:13
[Invoice_series] => VS
[Invoice_id] => 24
[Amount] => 10251
[Type] => Debit
[Method] => Sale
)
[21] => Array
(
[ID] => 50
[Create_date] => 2018-10-26
[Create_time] => 12:00:51
[Invoice_series] => SRT
[Invoice_id] => 9
[Amount] => 5000
[Type] => Credit
[Method] => sale_return
)
[22] => Array
(
[ID] => 52
[Create_date] => 2018-10-27
[Create_time] => 18:14:15
[Invoice_series] => SRT
[Invoice_id] => 11
[Amount] => 10251
[Type] => Credit
[Method] => sale_return
)
[23] => Array
(
[ID] => 1020
[Create_date] => 2018-11-23
[Create_time] => 17:30:14
[Payment_series] => RecT
[Payment_id] => 3
[Amount] => 9251
[Type] => Credit
[Method] => payment
)
[24] => Array
(
[ID] => 1021
[Create_date] => 2018-11-23
[Create_time] => 17:30:33
[Payment_series] => RecT
[Payment_id] => 4
[Amount] => 0
[Type] => Debit
[Method] => payment
)
[25] => Array
(
[ID] => 1016
[Create_date] => 2018-11-23
[Create_time] => 11:28:57
[Payment_series] => RecT
[Payment_id] => 1
[Amount] => 20251
[Type] => Credit
[Method] => payment
)
[26] => Array
(
[ID] => 1018
[Create_date] => 2018-11-23
[Create_time] => 16:08:17
[Payment_series] => RecT
[Payment_id] => 2
[Amount] => -20251
[Type] => Debit
[Method] => payment
)
)
PHP Code:
Sorted Time wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_time"]) - strtotime($b["Create_time"]);});
Sorted Date wise
usort($Ledgers, function( $a, $b ) {return strtotime($a["Create_date"]) - strtotime($b["Create_date"]);});
php
php
edited Nov 24 '18 at 11:31
Nick
30.6k121941
30.6k121941
asked Nov 24 '18 at 11:03
Rushabh ShahRushabh Shah
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you just concatenate date and time first
usort($Ledgers, function( $a, $b ) {
$create_a = strtotime($a["Create_date"].$a["Create_time"]);
$create_b = strtotime($b["Create_date"].$b["Create_time"]);
return $create_a - $create_b;
});
and use usort function once.
and also another solution use strcmp
to sort string
usort($Ledgers, function ($a, $b) {
return strcmp($a['Create_date'].$a['Create_time'], $b['Create_date'].$b['Create_time']);
});
You might want a space between the date and the time... also you can justreturn $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expectedstrtotime
to parse the string with no space between date and time.
– Nick
Nov 24 '18 at 12:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457464%2fhow-to-php-usort-based-on-date-and-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you just concatenate date and time first
usort($Ledgers, function( $a, $b ) {
$create_a = strtotime($a["Create_date"].$a["Create_time"]);
$create_b = strtotime($b["Create_date"].$b["Create_time"]);
return $create_a - $create_b;
});
and use usort function once.
and also another solution use strcmp
to sort string
usort($Ledgers, function ($a, $b) {
return strcmp($a['Create_date'].$a['Create_time'], $b['Create_date'].$b['Create_time']);
});
You might want a space between the date and the time... also you can justreturn $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expectedstrtotime
to parse the string with no space between date and time.
– Nick
Nov 24 '18 at 12:10
add a comment |
you just concatenate date and time first
usort($Ledgers, function( $a, $b ) {
$create_a = strtotime($a["Create_date"].$a["Create_time"]);
$create_b = strtotime($b["Create_date"].$b["Create_time"]);
return $create_a - $create_b;
});
and use usort function once.
and also another solution use strcmp
to sort string
usort($Ledgers, function ($a, $b) {
return strcmp($a['Create_date'].$a['Create_time'], $b['Create_date'].$b['Create_time']);
});
You might want a space between the date and the time... also you can justreturn $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expectedstrtotime
to parse the string with no space between date and time.
– Nick
Nov 24 '18 at 12:10
add a comment |
you just concatenate date and time first
usort($Ledgers, function( $a, $b ) {
$create_a = strtotime($a["Create_date"].$a["Create_time"]);
$create_b = strtotime($b["Create_date"].$b["Create_time"]);
return $create_a - $create_b;
});
and use usort function once.
and also another solution use strcmp
to sort string
usort($Ledgers, function ($a, $b) {
return strcmp($a['Create_date'].$a['Create_time'], $b['Create_date'].$b['Create_time']);
});
you just concatenate date and time first
usort($Ledgers, function( $a, $b ) {
$create_a = strtotime($a["Create_date"].$a["Create_time"]);
$create_b = strtotime($b["Create_date"].$b["Create_time"]);
return $create_a - $create_b;
});
and use usort function once.
and also another solution use strcmp
to sort string
usort($Ledgers, function ($a, $b) {
return strcmp($a['Create_date'].$a['Create_time'], $b['Create_date'].$b['Create_time']);
});
edited Nov 24 '18 at 14:57
answered Nov 24 '18 at 11:16
EK LYEK LY
2715
2715
You might want a space between the date and the time... also you can justreturn $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expectedstrtotime
to parse the string with no space between date and time.
– Nick
Nov 24 '18 at 12:10
add a comment |
You might want a space between the date and the time... also you can justreturn $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expectedstrtotime
to parse the string with no space between date and time.
– Nick
Nov 24 '18 at 12:10
You might want a space between the date and the time... also you can just
return $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
You might want a space between the date and the time... also you can just
return $create_a - $create_b;
– Nick
Nov 24 '18 at 11:34
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
i try to use space and without space. i get same result
– EK LY
Nov 24 '18 at 12:08
Interesting - I wouldn't have expected
strtotime
to parse the string with no space between date and time.– Nick
Nov 24 '18 at 12:10
Interesting - I wouldn't have expected
strtotime
to parse the string with no space between date and time.– Nick
Nov 24 '18 at 12:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457464%2fhow-to-php-usort-based-on-date-and-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown