الفصل الثالث
دالة الشرط للتبديل بين القيم Switch :
التحكم (الشروط والتكرار )
تستخدم دالة التبديل للاختيار بين عدة حالات لاحتمالات مختلفة ، وهي تقلل من تكرار خطوات البحث عن تحقق شرط ما ، والصيغة العامة لها هي :
Switch (variable) {
Case "string1":
Commands1
Break;
Case "string2":
Commands2 Break;
Case "string3":
Commands3 Break;
Case "string4":
Commands4 Break;
}
<?php $a="Osman";
Switch ($a) {
Case "Aly":
Echo " Welcome Aly, Your ID is Aly123"; Break;
Case "Ahmed":
Echo "Welcome Ahmed, Your ID is Ahmed321"; Break;
٦٧
ص ٦٧