How To Use Case When In Php

Tanggal : 13 Feb 2023, Category : Tutorial, Create By : admin

The switch statement in PHP can be used as an alternative to multiple if statements. The switch statement tests a variable or expression against multiple cases and executes the code for the matching case. Here's an example of using a switch statement in PHP:

$day_of_week = "Monday";

switch ($day_of_week) {
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
case "Wednesday":
echo "Today is Wednesday";
break;
default:
echo "Today is not Monday, Tuesday or Wednesday";
break;
}

In this example, the variable $day_of_week is tested against each case in the switch statement. If the value of $day_of_week is "Monday", the code in the first case will be executed and "Today is Monday" will be outputted. If the value of $day_of_week does not match any of the cases, the code in the default case will be executed.


Keyword:
  • How To Use Case When In Php

Artikel Lain

How To Use For In Java

Date : 15 Feb 2023, Category : Pemprograman Website, Create By : admin

In Java, the for loop has a slightly different syntax than in JavaScript. The for loop in Java can be used with an enhanced version called the "for-each" loop, which .....

The Difference Between The Python And Go Programming Languages

Date : 13 Feb 2023, Category : Pemprograman Website, Create By : admin

Python and Go are both popular programming languages, but they have different design goals, syntax, and areas of application. Design Goals: Python was designed to be a high-level, dynamically typed, interpreted language .....

What Are The Natural Ingredients That Can Make Your Skin Healthy And Bright?

Date : 11 Feb 2023, Category : Health, Create By : admin

Nowadays, everyone wants to have a face skin that is not only beautiful, but also healthy and naturally bright. However, exposure to sun rays containing ultraviolet which can cause dry .....