public function index()
{
$num = $this->request->param('num',35);
$box = [
['id'=>1,'name'=>'小箱','num'=>20],
['id'=>2,'name'=>'中箱','num'=>40],
['id'=>3,'name'=>'大箱','num'=>60],
];
$sortAscBox = Arr::sort($box,'num',SORT_ASC);
$maxBox = $sortAscBox[count($sortAscBox)-1];
$residue = $num % $maxBox['num'];
$arr = [];
if($num>=$maxBox['num']) {
$arr[$maxBox['id']] = array_merge($maxBox, [
'box_num' => intval(floor($num / $maxBox['num'])),
'residue' => 0,
]);
}
if($residue>0){
$index = Arr::findIndex(array_column($sortAscBox,'num'),$residue);
$findBox = $sortAscBox[$index];
if($findBox['id']==$maxBox['id']){
$arr[$maxBox['id']]['residue'] = $maxBox['num']-$residue;
}else{
$arr[$findBox['id']] = array_merge($findBox,[
'box_num' => intval(floor($residue / $findBox['num'])),
'residue' => $findBox['num']-$residue,
]);
}
}
dump($arr);exit;
}