我使用if else条件在$ total之前回显$指标。
但我收到了php错误
注意:未定义的变量:指标。
如何在不收到任何错误的情况下实现此目的,并根据if else条件获取黄色结果。有可能吗?
<?php
$total=6;
echo $indicator;
echo $total;
if($total<5) {
$indicator="red";
} else if($total>7) {
$indicator="green";
} else {
$indicator="yellow";
}
?>
答案 0 :(得分:0)
为什么不尝试这样
<强>更新强>
<?php
echo myFun();
function myFun(){
$total=6;
if($total<5){
$indicator="red";
}elseif($total>7){
$indicator="green";
}else{
$indicator="yellow";
}
return $indicator = $indicator.$total;
}