رمز `Switch` هو عبارة عن بيان تحديد سيحدد عبارة التبديل وينفذه من قائمة المرشحين. يتكون التبديل من `case``default` الاختياري. يمكن إيقاف التنفيذ باستخدام `break` أو `return` .
## بناء الجملة
`switch(x)
{
case value1:
//execute if x = value1
break;
case value2:
//execute if x = value2
break;
...
default:
execute if x is different with cases above
}
`
## مثال
`<?php
//initialize with a random integer within range
$diceNumber = mt_rand(1, 6);
//initialize
$numText = "";
//calling switch statement
switch($diceNumber)
{
case 1:
$numText = "One";
break;
case 2:
$numText = "Two";
break;
case 3:
case 4:
// case 3 and 4 will go to this line
$numText = "Three or Four";
break;
case 5:
$numText = "Five";
echo $numText;
// break; //without specify break or return it will continue execute to next case.