我在PHP中的if和else语句有一个问题,它从不运行else语句。
输入表单为HTML格式:
<input type="radio" name="marital_stat" id="single" value="single" />Single
<input type="radio" name="marital_stat" id="married" value="married" />Married
<input name="age" type="text" size="5" maxlength="3" placeholder="30" required/>
<input name="work" type="radio" id="employee" value="employee" />Employee
<input name="work" type="radio" id="own" value="own" />
Own Business
<input name="work" type="radio" id="jobless" value="jobless" />Jobless
<input name="place" type="radio" id="urban" value="urban" />Urban
<input name="place" type="radio" id="rural" value="rural" />Rural</td>以下是PHP代码:
if ($marital_stat == 'married')
{
if ($age >= 18 || $age < 59)
{
if ($work == 'jobless')
{
if ($place == 'rural') { $loan_credibility == 5; }
}
}
}
else if ($marital_stat == 'single')
{
if ($age >= 18 || $age < 59)
{
if ($work == 'employee')
{
if ($place == 'rural') { $loan_credibility == 1; }
}
}
}下面是一个将显示一些输出的条件:
$A = 'positive';
$B = 'negative';
if ($loan_credibility == 5 ){
echo $B ;}
else{
echo $A;
}发布于 2015-06-05 01:45:45
发布于 2015-06-05 01:21:44
您没有else子句(这在使用else if时在逻辑上是必需的)...
if (condition) {
code to be executed if condition is true;
} elseif (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}做以下任何事情(#1或#2最有意义)……
将您的子句更改为else
else子句<
if
else if to else<代码>G215
所以有两件事可以解决你的问题: 1) if-else if-else逻辑和2) = vs ==...
if ($marital_stat == 'married')
{
if ($age >= 18 || $age < 59)
{
if ($work == 'jobless')
{
if ($place == 'rural') { $loan_credibility = 5; }
}
}
}
if ($marital_stat == 'single')
{
if ($age >= 18 || $age < 59)
{
if ($work == 'employee')
{
if ($place == 'rural') { $loan_credibility = 1; }
}
}
}https://stackoverflow.com/questions/30648384
复制相似问题