Darry_
2017-02-16 15:00
<?php $totalMoney = 0;//总工资 $basicMoney = 300;//基本工资 $sex = "男"; $noHouse = TRUE; //是否有房 $houseMoney = 150;//住房补贴 $isPregnancy = TRUE; //是否怀孕 $pregnancyMoney = 100;//怀孕补贴 if($sex == "男") { $totalMoney = $basicMoney + 0;// 男的没奖金 if($noHouse) { $totalMoney = $totalMoney + $houseMoney; } } else if($sex == "女") { $totalMoney = $basicMoney + 300;// 女的有奖金300元 if($isPregnancy) { $totalMoney = $totalMoney + $pregnancyMoney; } } echo $totalMoney; ?>
这代码运行出的结果是450.没有错误。
只看倒数第二行,写了大半天,结果随便输出个工资竟然可以刷经验
<?php
$totalMoney = 0;//总工资
$basicMoney = 300;//基本工资
$sex = "男";
$noHouse = TRUE; //是否有房
$houseMoney = 150;//住房补贴
$isPregnancy = TRUE; //是否怀孕
$pregnancyMoney = 100;//怀孕补贴
if($sex =="男"){
if($noHouse){
$totalMoney=$houseMoney+$basicMoney;
}else{
$totalMoney=$basicMoney;
}
}else if($sex =="女"){
if($isPregnancy){
$totalMoney=$basicMoney+$isPregnancy;
}else{
$totalMoney=$basicMoney;
}
}
echo $basicMoney;
?>
//结果300也没有错误
PHP入门篇
455994 学习 · 6306 问题
相似问题
回答 2
回答 9
回答 4
回答 1
回答 3