Php遍历交换机,并通过

时间:2015-08-25 17:38:33

标签: php switch-statement

是否可以在php中执行以下操作:

switch ($option) {

    case "a":
      if($val == 7) {
          include("page.php");
      } else {
          "go to default case";
      }
    break;

    case "b":
      include("somefile.php");
    break;

    default:
     include("404.php");
    break;

}

在上面的情况“a”中,如果$ val == 7包含page.php,则otherwize转到默认开关案例

1 个答案:

答案 0 :(得分:2)

一种hackish方式(我会寻找更好的方式)但它看起来像这样:

switch ($option) {

    case "b":
      include("somefile.php");
    break;

    case "a":
      if($val == 7) {
          include("page.php");
          break;
      } else {
          // go to default case
      }

    default:
      include("404.php");
    break;
}
break时{p> $val == 7break goto并且默认为<{1}}。

IMO更加强硬的方式switch ($option) { case "a": if($val == 7) { include("page.php"); } else { goto notfound; } break; case "b": include("somefile.php"); break; default: notfound: include("404.php"); break; }

goto

所以简而言之,没有你不能跳入另一个案例或sub TemplateFiller(AHNSnumber as String) Dim wbk As Workbook Dim wbpath As String Dim lastline as long Dim wbName as string wbpath = "O:\08_Lean_Eng\10_On_going\David\Soldier's Pond\MDR\Templates\TemplateCustom.xls" 'This is to check if it's open first. Only open it if it is closed! 'IsWorkBookOpen is one of my own functions, not included here If IsWorkBookOpen(wbpath) = False Then Set wbk = Workbooks.Open(wbpath) 'Notice: set wbk =, not Set wbk as ElseIf IsWorkBookOpen(wbpath) = True Then wbName = "somethingworkbook.xlsb" Set wbk = Workbooks(wbName) End If 'Finding the last line in the other wbk (I'm using info from the other wbk for variables here) lastline = wbk.Sheets("DL001").Range("BG65000").End(xlUp).row + 1 wbk.Sheets("Dl001").Range("F" & lastline) = AHNSnumber 'Using a passed variable wbk.Sheets("Dl001").Range("G" & lastline) = "OK" 'Writing some stuff wbk.Sheets("Dl001").Range("H" & lastline) = ThisWorkbook.Sheets("a").Range("A1") 'Value from one to the other and vice versa Thisworkbook.sheets("b").Range("A2") = wbk.Sheets("Dl001").Range("A" & lastline) 'Changing a variable in this workbook ThisWorkbook.Sheets("Data").Range("Revision") = ThisWorkbook.Sheets("Data").Range("Revision") + 1 End sub 'I am not the original writer of this function. Function IsWorkBookOpen(filename As String) As Boolean Dim ff As Long, ErrNo As Long On Error Resume Next ff = FreeFile() Open filename For Input Lock Read As #ff Close ff ErrNo = Err On Error GoTo 0 Select Case ErrNo Case 0: IsWorkBookOpen = False Case 70: IsWorkBookOpen = True Case Else: Error ErrNo End Select End Function 。我可能会创建一个函数并在两个地方调用它。