Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

PHP Switch Statement

PHP Switch is a method that outputs a specific case depending on the value of a variable. It is another method which is similar to using if, else if and else statements.

The switch statement below looks for the value of the variable $var which is the variable $run which is ‘running’. Since the case is ‘running’, the output is ‘hello’.

$var = 25;
$run = 'running';
$var = $run;
switch ($var) {
    case 25:
        echo "hi ";
        break;
    case 'running':
        echo "hello ";
        break;
    default:
        echo "default";
        break;
}