php CASE Function code example

Example 1: switch case php

switch (fruit) {
  case apple:
    code to be executed if fruit=apple;
    break;
  case banana:
    code to be executed if fruit=banana;
    break;
    ...
  default:
    code to be executed if fruit is different from all fruits;
}

Example 2: switch case php

$fruit = "apple";
switch ($fruit) {
  case "apple":
    echo "doctor";
    break;
  case "banana":
    echo "monkey";
    break;
  default:
   	echo "things";
}//doctor

Example 3: php case switch

switch ($i) {
    case 0:
        echo "i ist gleich 0";
        break;
    case 1:
        echo "i ist gleich 1";
        break;
    case 2:
        echo "i ist gleich 2";
        break;
}

Tags:

Php Example