我有multidimentional数组,我想按employeeID&Dates和Dates排序。
我尝试了多种类型,但由于缺乏知识和mulisort数组的经验,因此无法正常使用..
这是数组
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
)
)
如果你看到,那么内部数组中有两个键EmployeeID和InDate。
我想使用两列对这个数组进行排序..我怎样才能使它成为可能?
- = - = - = - = - = - = - =
我试过PHP函数http://php.net/manual/en/function.array-multisort.php 但无法弄清楚如何使用它..
答案 0 :(得分:1)
您可以使用usort
或uasort
。它期望数组和一个对2个元素进行排序的回调。它必须返回一个大于/等于/低于零的整数,以将第一个元素映射为大于/等于/低于第二个元素。
$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
});