php数组\u multisort未对多维数组排序
好的,我有这个数组,我们称它为$array 现在,我有了一个按多个键对多维数组排序的函数php数组\u multisort未对多维数组排序,php,arrays,web,Php,Arrays,Web,好的,我有这个数组,我们称它为$array 现在,我有了一个按多个键对多维数组排序的函数 Array ( [0] => Array ( [id] => 7 [workorder_id] => 27 [truck_id] => 4 [event_type] => 1 [location_id] =>
Array
(
[0] => Array
(
[id] => 7
[workorder_id] => 27
[truck_id] => 4
[event_type] => 1
[location_id] =>
[location_name] => Billing Address
[address_address] => 123 Main Street
[address_city] => Montreal
[address_state] => QC
[address_zip] => A1A1A1
[address_country_id] => 1
[contact] => bob
[phone] => 555-555-555
[fax] => 555-555-555
[po] => 123131
[notes] =>
[appointment_from] => 2013-03-30 12:30:00
[appointment_to] => 2013-03-30 14:30:00
[crossdock] => 0
[status] => 1
)
[1] => Array
(
[id] => 8
[workorder_id] => 27
[truck_id] => 4
[event_type] => -1
[location_id] =>
[location_name] => Billing Address
[address_address] => 123 Main Street
[address_city] => Montreal
[address_state] => QC
[address_zip] => A1A1A1
[address_country_id] => 1
[contact] =>
[phone] => 555-555-555
[fax] =>
[po] =>
[notes] =>
[appointment_from] => 2013-04-04 06:00:00
[appointment_to] => 2013-04-04 12:00:00
[crossdock] => 0
[status] => 1
)
[2] => Array
(
[id] => 9
[workorder_id] => 27
[truck_id] => 4
[event_type] => 1
[location_id] =>
[location_name] => Billing Address
[address_address] => 123 Main Street
[address_city] => Montreal
[address_state] => QC
[address_zip] => A1A1A1
[address_country_id] => 2
[contact] => Jim Smith
[phone] => 555-555-555
[fax] => 555-555-555
[po] =>
[notes] =>
[appointment_from] => 2013-04-16 10:00:00
[appointment_to] => 2013-04-16 12:00:00
[crossdock] => 0
[status] => 1
)
)
所以,我想按事件类型进行排序,然后从日期开始约会。所以我运行这个函数:
function sort_multiple_keys($array,$key1,$key1_sort = SORT_DESC,$key2,$key2_sort = SORT_ASC){
$sort = array();
if(count($array) > 0){
foreach($array as $k=>$v) {
$first[$k] = $v[$key1];
$second[$k] = $v[$key2];
}
array_multisort($first, $key1_sort, $second, $key2_sort, $array);
}
unset($sort);
}
但是什么都没有
有什么帮助吗?您实际上并没有从排序函数返回值 您可以在结尾处
返回$array
;或者将其作为引用传入,使函数在原始实例而不是副本上工作;为此,您需要将函数定义更改为:
sort_multiple_keys($array,'event_type',SORT_DESC,'appointment_from',SORT_ASC);
您的函数需要返回值吗?不,它只运行数组排序。。但在我能做到这一点之前,我必须做转换。我从这里得到的示例如下:
function sort_multiple_keys(&$array,$key1,$key1_sort = SORT_DESC,$key2,$key2_sort = SORT_ASC){
^ tells PHP that this variable is by reference