有人可以给我一个解决方案,如何按订单号对多个数组进行排序吗?
$data['submain'][ 44 ][0] = array(
'title'=> 'title',
'order' => 2
);
$data['submain'][ 44 ][1] = array(
'title'=> 'title 2',
'order' => 1
);
$data['submain'][ 44 ][2] = array(
'title'=> 'title F',
'order' => 5
);
$data['submain'][ 44 ][3] = array(
'title'=> 'title F',
'order' => 2
);
foreach ($data['submain'] as $page_id => $page ){
usort($data['submain'][$page_id], function($a, $b) {
return $a['order'] - $b['order'];
});
//echo '<pre>';
//print_r($data['submain']);
}
答案 0 :(得分:0)
认为分享解决方案会很好:)
$output = [];
foreach ($data['submain'] as $page_id => $page ){
usort($page, function($a, $b) {
return $a['order'] - $b['order'];
});
$output[$page_id] = $page;
}
$data['submain'] = $output;
echo '<pre>';
print_r($data['submain']);