我对switch语句有疑问。
我想从两个switch语句中获取价值。
$status = $bill->status;
$capsules = '';
switch($status){
case Bill::STATUS_CREATED:
$capsules .= "<div class = \"ui grey tiny label\">Created</div>";
break;
case Bill::STATUS_SENT:
$capsules .= "<div class = \"ui blue tiny label\">Sent</div>";
break;
case Bill::STATUS_CANCELLED:
$capsules .= "<div class = \"ui red tiny label\">Cancelled</div>";
break;
default;
$capsules .= "";
}
switch ($status->Biil::getPaymentStatus()){
case 'paid':
$capsules .= "<div class=\"ui green tiny label\">Paid</div>";
break;
case 'partially':
$capsules .= "<div class=\"ui brown tiny label\">Partially Paid</div>";
break;
default:
$capsules .= "";
}
return $capsules;
如何使用一个返回值从两个switch语句获取数据??
答案 0 :(得分:0)
您可以尝试使用数组分别存储值。
$capsules = [];
switch ($status) {
case Bill::STATUS_CREATED:
$capsules[]= "<div class = \"ui grey tiny label\">Created</div>";
break;
case Bill::STATUS_SENT:
$capsules[]= "<div class = \"ui blue tiny label\">Sent</div>";
break;
case Bill::STATUS_CANCELLED:
$capsules[]= "<div class = \"ui red tiny label\">Cancelled</div>";
break;
default: // change ; to : here.
$capsules[] = "default value in first switch";
}
switch ($status->Bill::getPaymentStatus()) {
case 'paid':
$capsules[]= "<div class=\"ui green tiny label\">Paid</div>";
break;
case 'partially':
$capsules[]= "<div class=\"ui brown tiny label\">Partially Paid</div>";
break;
default:
$capsules[] = "default Value in Second switch.";
}
print_r($capsules); // print the value separately.