How do you handle huge if-conditions?

后端 未结 21 1738
一向
一向 2021-01-31 17:14

It\'s something that\'s bugged me in every language I\'ve used, I have an if statement but the conditional part has so many checks that I have to split it over multiple lines, u

21条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 17:35

    In reflective languages like PHP, you can use variable-variables:

    $vars = array('var1', 'var2', ... etc.);
    foreach ($vars as $v)
        if ($$v == true) {
            // do something
            break;
        }
    

提交回复
热议问题