ここにいくつかの疑似コードがあります(正しく書かれていません。私の ? のポイントは変数であり、スイッチではありません):
switch ($action) {
case "1":
//this is a function
case "2":
//this is a function
//etc.
}
これはどのように書かれるべきですか:
$variable = ケース 1 の関数の結果。
ここにいくつかの疑似コードがあります(正しく書かれていません。私の ? のポイントは変数であり、スイッチではありません):
switch ($action) {
case "1":
//this is a function
case "2":
//this is a function
//etc.
}
これはどのように書かれるべきですか:
$variable = ケース 1 の関数の結果。
あなたの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.
}
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.
?>
この例では、ケースの値を変数に入力する必要があります。