我试图在if-else条件下给名为<div class="form-item webform-component webform-component-radios" id="webform-component-discount-options">
<div id="edit-submitted-discount-options" class="form-radios">
<div class="form-item form-type-radio form-item-submitted-discount-options">
<input type="radio" id="edit-submitted-discount-options-1" name="submitted[discount_options]" value="none" class="form-radio">
<label class="option" for="edit-submitted-discount-options-1">Regular: $135 (1 Year) or $225 (2 Year) </label>
</div>
<div class="form-item form-type-radio form-item-submitted-discount-options">
<input type="radio" id="edit-submitted-discount-options-2" name="submitted[discount_options]" value="senior" class="form-radio">
<label class="option" for="edit-submitted-discount-options-2">Senior: $108 (1 Year) or $180 (2 Year) </label>
</div>
<div class="form-item form-type-radio form-item-submitted-discount-options">
<input type="radio" id="edit-submitted-discount-options-3" name="submitted[discount_options]" value="student" class="form-radio">
<label class="option" for="edit-submitted-discount-options-3">Student: $81 (1 Year) </label>
</div>
<div class="form-item form-type-radio form-item-submitted-discount-options">
<input type="radio" id="edit-submitted-discount-options-4" name="submitted[discount_options]" value="nonresident" class="form-radio">
<label class="option" for="edit-submitted-discount-options-4">Non-Resident: $108 (1 Year) or $180 (2 Year) </label>
</div>
</div>
</div>
的变量赋值,然后尝试在if-else条件之外调用$bonus
,所以真实条件的变量应为自动调用。我已经试过了这段代码,但是在laravel调试模式下却给了我一个错误
错误:
未定义变量:奖金
代码:
$bonus
答案 0 :(得分:2)
您必须定义$bonus
$bonus = 0;
if ($data->lend_amount >= 50 && $data->lend_amount <= 500) {
$bonus = ($data->lend_amount * 4) / 100;
} else if ($data->lend_amount >= 500 && $data->lend_amount <= 50000) {
$bonus = ($data->lend_amount * 5) / 100;
}
或在最后一个else块中设置默认值
if ($data->lend_amount >= 50 && $data->lend_amount <= 500) {
$bonus = ($data->lend_amount * 4) / 100;
} else if ($data->lend_amount >= 500 && $data->lend_amount <= 50000) {
$bonus = ($data->lend_amount * 5) / 100;
} else {
$bonus = 0;
}