Thuta Learning
PHP
IntermediateProgrammingbeginner

Switch

switch statement က value တစ်ခုကို case များစွာနဲ့တိုက်စစ်ဖို့သုံးပါတယ်။ Role, status, selected menu, payment state စတာတွေကို handle လုပ်ရာမှာရှင်းပါတယ်။

php
<?php
$status = "paid";

switch ($status) {
  case "pending":
    echo "Payment is still pending.";
    break;
  case "paid":
    echo "Payment received. Prepare the order.";
    break;
  case "cancelled":
    echo "Order was cancelled.";
    break;
  default:
    echo "Unknown payment status.";
}
?>
You should see
Payment received. Prepare the order.

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Case value spelling မတူရင် default ထဲကျသွားနိုင်ပါတယ်။
Switch | Thuta Learning