1 回答
TA贡献1868条经验 获得超4个赞
您可以尝试以下代码。
foreach (post('title') as $key => $title) {
$arr = [
'title' => $title,
'address' => $address[$key],
'phone' => $phone[$key],
];
if (post('sub_email_' . $key) != null) {
if (post('sub_email_' . $key)) {
$submenu = [];
$subphone = post('sub_phone_' . $key);
$submap = post('sub_map_' . $key);
$submaps = post('sub_maps_' . $key);
foreach (post('sub_email_' . $key) as $k => $subemail) {
if (($subphone[$k] != null) && ($submap[$k] != null) && ($submaps[$k] != null)) {
$submenu[] = [
'email' => $subemail,
'phone' => $subphone[$k],
'map' => $submap[$k],
'maps' => $submaps[$k]
];
}
}
if (count($submenu) > 0) {
$arr['submenu'] = $submenu;
}
}
}
$menu[] = $arr;
}
$result=DB::table('menu')
->insert([
'menu_title' =>$menu_title,//your menu title here
'menu_content' => json_encode($menu)
]);
我希望它对你有用。
- 1 回答
- 0 关注
- 116 浏览
添加回答
举报