Maison >développement back-end >tutoriel php > 怎么合并多个if条件
如何合并多个if条件
如题:代码效率不高,冗余太多,在线等。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> if($start_id == $first_id && $arrive_id == '') { echo "我是第一个城市城市"; //去查询第一个城市是否添加了交通工具 $start_id = ''; $arrive_id = $first_id; $res = $this->model->get_traffic($tripid, $type, $start_id, $arrive_id); if($res) { $affected_rows = $this->model->update_traffic($traffic, $tripid, $type, $start_id, $arrive_id); if($affected_rows > 0) { echo "更新成功!"; } }else{ $trafficid = $this->model->add_traffic($traffic, $tripid, $start_id, $arrive_id, $type, $dateline); if($trafficid > 0) { echo '添加成功'; } } exit; } if($start_id == $last_id && $arrive_id == '') { echo "我是最后一个城市"; $start_id = $last_id; $arrive_id = ''; $res = $this->model->get_traffic($tripid, $type, $start_id, $arrive_id); if($res) { $affected_rows = $this->model->update_traffic($traffic, $tripid, $type, $start_id, $arrive_id); if($affected_rows > 0) { echo "更新成功!"; } }else{ $trafficid = $this->model->add_traffic($traffic, $tripid, $start_id, $arrive_id, $type, $dateline); if($trafficid > 0) { echo '添加成功'; } } exit; } if($start_id == '' && $arrive_id == '') { echo "需选择2个城市才能添加交通工具"; }else{ echo "选择正确可以入库"; $res = $this->model->get_traffic($tripid, $type, $start_id, $arrive_id); if($res) { $affected_rows = $this->model->update_traffic($traffic, $tripid, $type, $start_id, $arrive_id); if($affected_rows > 0) { echo "更新成功!"; } }else{ $trafficid = $this->model->add_traffic($traffic, $tripid, $start_id, $arrive_id, $type, $dateline); if($trafficid > 0) { echo '添加成功'; } } } } $this->display = true; $this->view->assign('cities', $cities); $this->view->assign('traffic', $_config['traffic']); $this->view->assign('tripid', $tripid); $this->view->assign('cityid', $cityid); $this->view->assign('type', $type); }else if($type == 2) { echo "我是来添加景点美食绿色的"; }