Reputation: 6070
i have multidimentional array which i want to sort by both employeeID's and Dates also.
i have tried multisort, but due to lack of knowedge and experience in mulisort array can't use it properly..
Here is the Array
Array
(
[1::2014-02-01] => Array
(
[EmployeeID] => 1
[InTime] => 15:44:16
[InDate] => 2014-02-01
[OutTime] => 17:36:19
[OutDate] => 2014-03-06
[YearID] => 16
[MonthID] => 2
[AttendanceStatus] => 2
)
[5::2014-02-05] => Array
(
[EmployeeID] => 5
[InTime] => 16:26:49
[InDate] => 2014-02-05
[OutTime] => 11:08:46
[OutDate] => 2014-10-23
[YearID] => 16
[MonthID] => 2
[AttendanceStatus] => 2
)
[8::2014-02-09] => Array
(
[EmployeeID] => 8
[InTime] => 20:39:15
[InDate] => 2014-02-09
[OutTime] => 02:56:07
[OutDate] => 2015-02-17
[YearID] => 16
[MonthID] => 2
[AttendanceStatus] => 2
)
[6::2014-02-22] => Array
(
[EmployeeID] => 6
[InTime] => 08:25:34
[InDate] => 2014-02-22
[OutTime] => 15:23:28
[OutDate] => 2014-04-28
[YearID] => 16
[MonthID] => 2
[AttendanceStatus] => 2
)
[1::2014-04-11] => Array
(
[EmployeeID] => 1
[InTime] => 06:50:13
[InDate] => 2014-04-11
[OutTime] => 05:11:56
[OutDate] => 2014-05-24
[YearID] => 16
[MonthID] => 4
[AttendanceStatus] => 2
)
[9::2014-05-07] => Array
(
[EmployeeID] => 9
[InTime] => 07:24:11
[InDate] => 2014-05-07
[OutTime] => 11:21:32
[OutDate] => 2014-07-23
[YearID] => 16
[MonthID] => 5
[AttendanceStatus] => 2
)
[9::2014-05-17] => Array
(
[EmployeeID] => 9
[InTime] => 21:45:48
[InDate] => 2014-05-17
[OutTime] => 09:33:54
[OutDate] => 2015-02-27
[YearID] => 16
[MonthID] => 5
[AttendanceStatus] => 2
)
[11::2014-06-03] => Array
(
[EmployeeID] => 11
[InTime] => 13:58:48
[InDate] => 2014-06-03
[OutTime] => 16:01:42
[OutDate] => 2014-06-18
[YearID] => 16
[MonthID] => 6
[AttendanceStatus] => 2
)
[8::2014-07-21] => Array
(
[EmployeeID] => 8
[InTime] => 15:40:51
[InDate] => 2014-07-21
[OutTime] => 03:54:36
[OutDate] => 2014-07-14
[YearID] => 16
[MonthID] => 7
[AttendanceStatus] => 2
)
[9::2014-08-16] => Array
(
[EmployeeID] => 9
[InTime] => 06:23:50
[InDate] => 2014-08-16
[OutTime] => 06:21:06
[OutDate] => 2014-04-10
[YearID] => 16
[MonthID] => 8
[AttendanceStatus] => 2
)
[1::2014-09-23] => Array
(
[EmployeeID] => 1
[InTime] => 06:19:24
[InDate] => 2014-09-23
[OutTime] => 23:10:20
[OutDate] => 2015-09-26
[YearID] => 16
[MonthID] => 9
[AttendanceStatus] => 2
)
[3::2014-10-03] => Array
(
[EmployeeID] => 3
[InTime] => 04:15:26
[InDate] => 2014-10-03
[OutTime] => 11:55:38
[OutDate] => 2015-07-31
[YearID] => 16
[MonthID] => 10
[AttendanceStatus] => 2
)
[1::2014-10-19] => Array
(
[EmployeeID] => 1
[InTime] => 09:43:12
[InDate] => 2014-10-19
[OutTime] => 02:51:56
[OutDate] => 2015-05-03
[YearID] => 16
[MonthID] => 10
[AttendanceStatus] => 2
)
[8::2014-11-08] => Array
(
[EmployeeID] => 8
[InTime] => 11:54:25
[InDate] => 2014-11-08
[OutTime] => 06:55:01
[OutDate] => 2014-12-25
[YearID] => 16
[MonthID] => 11
[AttendanceStatus] => 2
)
[1::2014-11-28] => Array
(
[EmployeeID] => 1
[InTime] => 20:25:13
[InDate] => 2014-11-28
[OutTime] => 21:46:02
[OutDate] => 2015-07-31
[YearID] => 16
[MonthID] => 11
[AttendanceStatus] => 2
)
[8::2015-01-30] => Array
(
[EmployeeID] => 8
[InTime] => 01:19:49
[InDate] => 2015-01-30
[OutTime] => 09:20:37
[OutDate] => 2014-06-03
[YearID] => 17
[MonthID] => 1
[AttendanceStatus] => 2
)
[11::2015-02-17] => Array
(
[EmployeeID] => 11
[InTime] => 03:59:12
[InDate] => 2015-02-17
[OutTime] => 01:49:12
[OutDate] => 2015-06-05
[YearID] => 17
[MonthID] => 2
[AttendanceStatus] => 2
)
[6::2015-02-27] => Array
(
[EmployeeID] => 6
[InTime] => 06:45:15
[InDate] => 2015-02-27
[OutTime] => 22:49:19
[OutDate] => 2014-04-17
[YearID] => 17
[MonthID] => 2
[AttendanceStatus] => 2
)
[3::2015-05-18] => Array
(
[EmployeeID] => 3
[InTime] => 10:55:10
[InDate] => 2015-05-18
[OutTime] => 18:59:54
[OutDate] => 2015-04-02
[YearID] => 17
[MonthID] => 5
[AttendanceStatus] => 2
)
[5::2015-09-16] => Array
(
[EmployeeID] => 5
[InTime] => 19:46:53
[InDate] => 2015-09-16
[OutTime] => 07:52:40
[OutDate] => 2014-04-08
[YearID] => 17
[MonthID] => 9
[AttendanceStatus] => 2
)
[11::2015-10-16] => Array
(
[EmployeeID] => 11
[InTime] => 01:03:57
[InDate] => 2015-10-16
[OutTime] => 20:52:36
[OutDate] => 2014-11-25
[YearID] => 17
[MonthID] => 10
[AttendanceStatus] => 2
)
[6::2015-12-29] => Array
(
[EmployeeID] => 6
[InTime] => 04:29:13
[InDate] => 2015-12-29
[OutTime] => 21:02:34
[OutDate] => 2014-05-10
[YearID] => 17
[MonthID] => 12
[AttendanceStatus] => 2
)
[1::2014-09-20] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[1::2014-09-21] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[1::2014-09-22] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[1::2014-09-24] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[1::2014-09-25] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[1::2014-09-26] => Array
(
[EmployeeID] => 1
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-20] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-21] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-22] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-23] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-24] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-25] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[5::2014-09-26] => Array
(
[EmployeeID] => 5
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-20] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-21] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-22] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-23] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-24] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-25] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[8::2014-09-26] => Array
(
[EmployeeID] => 8
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-20] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-21] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-22] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-23] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-24] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-25] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[6::2014-09-26] => Array
(
[EmployeeID] => 6
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-20] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-21] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-22] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-23] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-24] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-25] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[9::2014-09-26] => Array
(
[EmployeeID] => 9
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-20] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-21] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-22] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-23] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-24] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-25] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[11::2014-09-26] => Array
(
[EmployeeID] => 11
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-20] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-20
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-21] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-21
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-22] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-22
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-23] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-23
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-24] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-24
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-25] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-25
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
[3::2014-09-26] => Array
(
[EmployeeID] => 3
[InTime] => 00:00:00
[InDate] => 2014-09-26
[OutTime] => 00:00:00
[OutDate] => 0000-00-00
[AttendanceStatus] => 2
[YearID] => 16
[MonthID] => 9
)
)
Here There Are Two Keys EmployeeID and InDate inside inner arrays if you see.
I want to sort this array using both columns.. How can i make it possible??
-=-=-=-=-=--=--=
I tried PHP function http://php.net/manual/en/function.array-multisort.php But couldn't Figure Out How to work with it..
Upvotes: 0
Views: 59
Reputation: 8474
You can use usort
or uasort
. It expects the array and a callback which sorts 2 elements. It has to return an integer greater/equal/lower zero to map the first element as greater/equal/lower than the second element.
$arr = ...; // your array
// the callback has to return integer greater/equal/lower zero
uasort($arr, function($e1, $e2){
return $el1['EmployeeID'] != $el2['EmployeeID'] ? // not equal
$el1['EmployeeID'] - $el2['EmployeeID'] : // return the difference (which maps to greater or lower)
strtotime($el1['InDate']) - strtotime($el2['InDate']) // When both IDs equal use InDate for sorting
});
Upvotes: 1