“Commutation PHP” Réponses codées

interrupteur PHP

$age=20;
switch ($age) {
	case 19:
        echo "Age is 18";
        break;
    case 20:
        echo "Age is 20";
        break;
    case 21:
        echo "Age is 21";
        break;
}
Grepper

Variables PHP Switch 2

switch ([$color, $size]) {
    case ['blue', 'small']:
        echo 'blue and small';
    break;

    case ['red', 'large'];
        echo 'red and large';
    break;
}
Mohamed Sami khiari

Commutation PHP

switch ($element) {
    case 0:
        echo "i es igual a 0";
        break;
    case 1:
        echo "i es igual a 1";
        break;
    case 2:
        echo "i es igual a 2";
        break;
}
CharllierJr

Déclaration de cas en php


<?php
switch ($i) {
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
}
?>

Fantastic Fly

Instruction de commutation PHP

<?php

  /*
  We use the switch statement to select any one of many blocks to be
  executed.
  Here is an example:
  */
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;
}

  /*
  You assign it a variable.
  Here is an example of it being used
  */

  $polygon = 12

  switch ($polygon) {
  case 12:
    echo "Dodecagon";
    break;
  case 18:
    echo "Octadecagon";
    break;
  case 42:
    echo "Tetracontakaidigon";
    break;
  default:
    echo "Enneacontakaihexagon";
  }
?>
Rick Astley

tableau de cas de commutateur PHP

foreach ($array[0] as $key => $value) {
    switch ($key) {
        case 'Products' :
            // do something
            break ;
        case 'customers' :
            // do something
            break ;
        case 'Models' :
            // do something
            break ;
     }
 }
Grevil

Réponses similaires à “Commutation PHP”

Questions similaires à “Commutation PHP”

Plus de réponses similaires à “Commutation PHP” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code