2017-08-13 7 views
0
$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') 
条件を見つけようとしています

私のアプローチは正しいですか、私はmisisng somethです上記の2つの条件が機能しないためですか?

related post

+1

$description_radio_box

変更

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

にあるラジオボタンの値を割り当てますか?達成しようとしていること。あなたの質問は明確ではありません –

+0

何をしようとしているのかまだ分かりませんが、ここであなたの三者は説明しました: '$ description_radio_box = $ instance ['what_to_check_for']? 'check_for_counter': 'check_for_image'; ' '$ instance [' what_to_check_for ']'がtrue(http://php.net/manual/en/types.comparisons.php)と評価された場合、 '$ description_radio_box'は'check_for_counter'という値を割り当てました。それ以外の場合、 '$ description_radio_box'には' 'check_for_image ''という値が割り当てられます。 – Kita

答えて

1

あなたは割り当て値のために三項演算子を追加する必要はありません。あなたのラジオボタンには、check_for_countercheck_for_imageのような値が入っています。単に

三項演算子の条件がある
$description_radio_box = $instance[ 'what_to_check_for' ];