三元运算符有三个选项

时间:2016-03-16 11:01:23

标签: php ternary-operator ternary

我试图建立一个三元运算符:

  • 如果按钮是== red-btn,则red-btn== white-btn放在班级中

  • 如果按钮是white-btn,则== grey-btngrey-btn放在班级中

  • 如果按钮是== red-btn,则red-btnred-btn, white-btn or grey-btn放在班级中

  • 如果按钮为printf("<a class=\"%s\"href=\"%s\">%s</a></div>\n", $colour=="red-btn"?"red-btn": $colour=="white-btn"?"white-btn\": $colour=="grey-btn"?"grey-btn"", $button_link_url, $button_title); ,则为 row = sheet.getRow(RowNo); // RowNo on which Row cell should have appeared cell = row.getCell(CellNo); // CellNo on which Position cell should have appeared on Row cell.setCellValue("031642153283700100"); // You could also get CellFormula by using cell.getCellFormula(); 等。

因此,它会检查用户从我的自定义字段套件下拉选项中选择的三个选项之一,该选项会根据用户选择输出proc sort data=have; by y; run; data want; set have; do while (rif<=lag(rif)); Part=1; end; if Part ne 1 then Part=2 run;

这是我的代码:

a2enmod rewrite

我知道这是错的,但需要帮助正确写出来。

4 个答案:

答案 0 :(得分:1)

我认为你需要更多括号。像这样的东西

printf("<a class=\"%s\" href=\"%s\">%s</a></div>\n",
    ($colour=="red-btn")?"red-btn":(
        ($colour=="white-btn")?"white-btn":(
            ($colour=="grey-btn")?"grey-btn":""
        )
    ),
    $button_link_url,
    $button_title
);

答案 1 :(得分:0)

foreach($buttons as $button){
                        //var_dump($button);
                        $button_title = $button['button_title'];
                        $button_link_url = $button['button_link_url'];
                        $colour = $button['colour'];

                        reset($colour);
                        $first_colour = key($colour);

                        var_dump($first_colour);
                        printf("<a class='%s' href='%s'>%s</a>\n",
                            ($first_colour=="Red")?"red-btn":(
                                ($first_colour=="White")?"white-btn":(
                                    ($first_colour=="Grey")?"grey-btn":""
                                )
                            ),
                            $button_link_url,
                            $button_title
                        );
                    }

答案 2 :(得分:0)

我试图使用3种条件来做同样的事情,所以这就是我所做的:

def display_game(game, grid_size):
    c = 65

    # First row
    print(f"  ", end='')
    for j in range(grid_size):
        print(f"| {j+1} ", end='')
    print(f"| ", end='')
    print()
    print(f'{(7*4+4)*"-"}')

    # Other rows
    for i in range(grid_size):
        print(f"{chr(c+i)} ", end='')
        for j in range(grid_size):
            print(f"| {game} ", end='')
        print(f"| ", end='')
        print()
        print(f'{(7*4+4)*"-"}')

display_game('~',7)

答案 3 :(得分:-1)

这是另一个没有回答所述问题的选项(关于三元运算符),但可能会回答关于将正确的类放在html中的基本问题

printf("<a class='%s' href='%s'>%s</a></div>\n",
    $colour,
    $button_link_url,
    $button_title
);