[英]Echo variable first and assign variable values later in php
我使用 if else 條件在 $total 之前回顯 $indicator。
但我收到 php 錯誤
注意:未定義變量:指標。
我如何在沒有任何錯誤的情況下實現這一點,並根據 if else 條件得到我的結果,該結果將是黃色的。 是否可以?
<?php
$total=6;
echo $indicator;
echo $total;
if($total<5) {
$indicator="red";
} else if($total>7) {
$indicator="green";
} else {
$indicator="yellow";
}
?>
你為什么不試試這個
更新
<?php
echo myFun();
function myFun(){
$total=6;
if($total<5){
$indicator="red";
}elseif($total>7){
$indicator="green";
}else{
$indicator="yellow";
}
return $indicator = $indicator.$total;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.