php case if 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: php switich

switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
}

Tags:

Php Example