我收到了带有多个数据集的laravel请求表单数据,例如:-
array:5 [▼
"start_date" => array("2019-01-01","2019-01-02","2019-01-03");
"planned" => array("1","2","3");
"planned_inc" => array("2","8","16.5");
"actual_inc" => array:10("7.9","1.2","3.6");
]
我想操纵像这样的数据集:-
$data = ['2019-01-01', '1', '2', '7.9'];
$formData = request(['start_date', 'planned', 'planned_incr', 'actual_incr' ,'actual']);
dd($formData);
foreach ($formData as $data) {
$jso = $data['start_date'];
$da = $data['planned'];
print_r($da);
}
答案 0 :(得分:1)
我认为您想将$formData
转换为多维数组,如下所示:
$dataSet = [];
foreach ($formData['start_date'] as $key=> $value) {
$dataSet[] = array(
'start_date' => $value,
'planned' => (isset($formData['planned'][$key]) ? $formData['planned'][$key]: ''),
'planned_inc' => (isset($formData['planned_inc'][$key]) ? $formData['planned_inc'][$key]: ''),
'actual_inc' => (isset($formData['actual_inc'][$key]) ? $formData['actual_inc'][$key]: ''),
);
}
print_r($dataSet);