开发者

Is there a more concise way of writing this simple PHP conditional?

开发者 https://www.devze.com 2023-01-28 10:10 出处:网络
It se开发者_Go百科ems like there would be a shorter way of writing this: if ($action == \'add\' || $action == \'update\' || $action == \'delete\') {

It se开发者_Go百科ems like there would be a shorter way of writing this:

if ($action == 'add' || $action == 'update' || $action == 'delete') {
       // whatever
}

is there?


if (in_array($action, array('add', 'update', 'delete'))) {
    // whatever
}


I prefer this form, since it is easier to maintain:

if(in_array($action, array('add', 'update', 'delete'))) {

}
0

精彩评论

暂无评论...
验证码 换一张
取 消