我有这样的php对象:
$test
->key1(1)
->key2(1)
->key3(1);
是否可以在其中添加条件?
像这样: $test
if(true) ->key1(1)
->key2(1)
if(true) ->key3(1);
答案 0 :(得分:0)
你想要的是
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
例如
if ($YOUR_KEY == "key1") {
//if key1 then do something
} elseif ($YOUR_KEY == "key2") {
//if key2 then do something
} else {
//if none condition work than do something else
}
此处$YOUR_KEY
是您的变量,"key1"
是您的值