这里有一些伪代码(它没有正确写入,我的点是变量,而不是开关):
switch ($action) {
case "1":
//this is a function
case "2":
//this is a function
//etc.
}
应该怎么写:
$ variable =案例1中的函数结果。
答案 0 :(得分:0)
您的 switch
声明错误。每个案例
break
关键字
$action = 1;
$result = "Success";
switch ($action) {
case 1:
$variable = $result;
echo $variable;//prints Success
//this is a function
break; // like this
case 2:
//this is a function
break;//
//etc.
}
答案 1 :(得分:0)
只需运行函数(您也可以传递args)作为case / break块中代码的一部分,如下所示:
$action = 1;
switch ($action) {
case 1:
$variable = someFunctionOne();
break;
case 2:
$variable = someOtherFunctionTwo();
break;
//etc.
}
答案 2 :(得分:0)
如何改变php切换的结果。 例如:
<?php
//variables of cases
$var_1 = 1;
$var_2 = 2;
$var_3 = 3;
$var_0 = 0;
//end variables of cases
//action variable
$action = 10;
//end action variable
//start switch
switch ($action) {
case "1":
echo "$var_1;";
break;
case "2":
echo "$var_2;";
break;
case "3":
echo "$var_3;";
break;
default:
echo "$var_0;";
}
//receives the value of the switch.
$switch_result = get_result_case;
//in this my example I need to enter the value of the case in a variable.
?>
在我的示例中,我需要在变量中输入案例的值。