$taste = empty($_post['taste'])?1:trim($_post['taste']);$drink = empty($_post['drink'])?0:trim($_post['drink']);$drink_quantity = empty($_post['drink_quantity'])?0:trim($_post['drink_quantity']);$potation = empty($_post['potation'])?0:trim($_post['potation']);$coffee = empty($_post['coffee'])?0:trim($_post['coffee']);$smoke = empty($_post['smoke'])?0:trim($_post['smoke']);$medicine_type = empty($_post['medicine_type'])?0:trim($_post['medicine_type']);$movement = empty($_post['movement'])?0:trim($_post['movement']);$movement_name = empty($_post['movement_name'])?'':trim($_post['movement_name']);$work = empty($_post['work'])?0:trim($_post['work']);$pressure = empty($_post['pressure'])?0:trim($_post['pressure']);$tired = empty($_post['tired'])?0:trim($_post['tired']);$cold = empty($_post['cold'])?0:trim($_post['cold']);$hands = empty($_post['hands'])?0:trim($_post['hands']);$pregnant = empty($_post['pregnant'])?0:trim($_post['pregnant']);$lactation = empty($_post['lactation'])?0:trim($_post['lactation']);$edema = empty($_post['edema'])?0:trim($_post['edema']);$edema_po = empty($_post['edema_po']) ? 0 : trim($_post['edema_po']);$discomfort = empty($_post['discomfort']) ? 0 : trim($_post['discomfort']);$makeup_name = empty($_post['makeup_name']) ? '' : trim($_post['makeup_name']);$shaping_name = empty($_post['shaping_name']) ? 0 : trim($_post['shaping_name']);$shaping = empty($_post['shaping']) ? 0 : trim($_post['shaping']);$skin = empty($_post['skin']) ? 0 : trim($_post['skin']);$skin_pro = empty($_post['skin_pro']) ? array() : $_post['skin_pro'];$skin_pro = implode(',',$skin_pro);$body_pro = empty($_post['body_pro']) ? array() : $_post['body_pro'];$body_pro = implode(',', $body_pro);$course = empty($_post['course']) ? 0 : trim($_post['course']);$nursing_period = empty($_post['nursing_period']) ? 0 : trim($_post['nursing_period']);$nursing_inter = empty($_post['nursing_inter']) ? 0 : trim($_post['nursing_inter']);$treatment_cost = empty($_post['treatment_cost']) ? 0 : trim($_post['treatment_cost']);$homep_roducts = empty($_post['homep_roducts']) ? 0 : trim($_post['homep_roducts']);
回复内容: $age = empty($_post['age'])?1:trim($_post['age']);
$taste = empty($_post['taste'])?1:trim($_post['taste']);$drink = empty($_post['drink'])?0:trim($_post['drink']);$drink_quantity = empty($_post['drink_quantity'])?0:trim($_post['drink_quantity']);$potation = empty($_post['potation'])?0:trim($_post['potation']);$coffee = empty($_post['coffee'])?0:trim($_post['coffee']);$smoke = empty($_post['smoke'])?0:trim($_post['smoke']);$medicine_type = empty($_post['medicine_type'])?0:trim($_post['medicine_type']);$movement = empty($_post['movement'])?0:trim($_post['movement']);$movement_name = empty($_post['movement_name'])?'':trim($_post['movement_name']);$work = empty($_post['work'])?0:trim($_post['work']);$pressure = empty($_post['pressure'])?0:trim($_post['pressure']);$tired = empty($_post['tired'])?0:trim($_post['tired']);$cold = empty($_post['cold'])?0:trim($_post['cold']);$hands = empty($_post['hands'])?0:trim($_post['hands']);$pregnant = empty($_post['pregnant'])?0:trim($_post['pregnant']);$lactation = empty($_post['lactation'])?0:trim($_post['lactation']);$edema = empty($_post['edema'])?0:trim($_post['edema']);$edema_po = empty($_post['edema_po']) ? 0 : trim($_post['edema_po']);$discomfort = empty($_post['discomfort']) ? 0 : trim($_post['discomfort']);$makeup_name = empty($_post['makeup_name']) ? '' : trim($_post['makeup_name']);$shaping_name = empty($_post['shaping_name']) ? 0 : trim($_post['shaping_name']);$shaping = empty($_post['shaping']) ? 0 : trim($_post['shaping']);$skin = empty($_post['skin']) ? 0 : trim($_post['skin']);$skin_pro = empty($_post['skin_pro']) ? array() : $_post['skin_pro'];$skin_pro = implode(',',$skin_pro);$body_pro = empty($_post['body_pro']) ? array() : $_post['body_pro'];$body_pro = implode(',', $body_pro);$course = empty($_post['course']) ? 0 : trim($_post['course']);$nursing_period = empty($_post['nursing_period']) ? 0 : trim($_post['nursing_period']);$nursing_inter = empty($_post['nursing_inter']) ? 0 : trim($_post['nursing_inter']);$treatment_cost = empty($_post['treatment_cost']) ? 0 : trim($_post['treatment_cost']);$homep_roducts = empty($_post['homep_roducts']) ? 0 : trim($_post['homep_roducts']);
这是一段有问题的代码...
把empty()换成isset()...
否则会有notice...
运用三元运算符也就是语句中的 ? : ;,用empty判断是否为空
一堆变量判空,非空去空格
? : 这个操作符你去了解一下
这段代码就是从post的表单数据中获取数据
主要做了空值校验 第一行代码的意思是如果_post数组里的taste为空 $taste变量赋1 否则为表单数据
其他代码差不多这个意思 还有就是implode是把传递过来的字符串按,分割 切割成数组
类似xx?a:b的格式叫做三目运算符
$v=empty(xxxx)?a:b
$v是一个变量
= 号是赋值符
empty(xxxx)? 相当于一个判断。empty是判断是否为空的函数
如果xxxx为空则$v的值赋值为a
如果xxxx不为空则$v的值赋值为b
反对高票答案, 原因如下:
