单选按钮价值困境

时间:2017-08-13 08:55:27

标签: php wordpress if-statement

$instance['what_to_check_for']   = sanitize_text_field($new_instance['what_to_check_for']);

现在我试图通过三元运营商做点什么→

$description_radio_box = $instance[ 'what_to_check_for' ] ? 'check_for_counter' : 'check_for_image';

基本上我想找个条件→

<?php if( $description_radio_box == 'check_for_counter' ){ ?>

                <?php if( $description_radio_box == 'check_for_image' )

我的方法是正确的还是我错了,因为上述两种情况都不起作用?

related post

1 个答案:

答案 0 :(得分:1)

您无需为分配值添加三元运算符。作为您的单选按钮,它自身包含check_for_countercheck_for_image等值。只需将单选按钮值指定给$description_radio_box

即可

变化

$description_radio_box = $instance[ 'what_to_check_for' ] ? 'check_for_counter' : 'check_for_image';

$description_radio_box = $instance[ 'what_to_check_for' ];