2016-05-13 9 views
0

変数をチェックしている変数の内部に三項演算子を使用することは可能ですか?説明する正しい方法がわからないので、私が意味したのは。変数文字列に三項演算子を使用する

$drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/'.($vbulletin->options['drc_embed_vine_smpl']) ? simple : postcard.'" width="480" height="480" frameborder="0"></iframe>'; 

このVARだけで設定がオンまたはオフ、1またはゼロ

$vbulletin->options['drc_embed_vine_smpl'] 

を返すブール値です。しかしそれは、私がどれだけかどうかを知る必要があり役に立たない情報だかどうかをチェックしているIここで三項演算子を使うことができます。

基本的に私はこの単純化しようとしています:これが可能である場合

if ($vbulletin->options['drc_embed_vine_smpl']) { 
    $drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/simple" width="480" height="480" frameborder="0"></iframe>'; 
    } else { 
    $drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/postcard" width="480" height="480" frameborder="0"></iframe>'; 
    } 

を、私が間違って何をやっていますか?あなたはそれらの内部paranthesisを囲む必要があり

+0

ただ、括弧内に囲みます。 '$ drc_embed_vine = '​​';' – Thamilan

答えて

0

を置きます。また、あなたは簡単で、はがきのための引用符が欠落しています

$drc_embed_vine = '<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options['drc_embed_vine_smpl']) ? "simple" : "postcard").'" width="480" height="480" frameborder="0"></iframe>'; 
                  ^           ^  ^  ^
+0

説明してくれてありがとうございます=)"単純な ":"はがき "ちょうど三項演算子を使い始めました。 –

0
$drc_embed_vine=($vbulletin->options['drc_embed_vine_smpl'])?'<iframe src="https://vine.co/v/$2/embed/simple" width="480" height="480" frameborder="0"></iframe>':'<iframe src="https://vine.co/v/$2/embed/postcard" width="480" height="480" frameborder="0"></iframe>'; 

またはいくつかの余分な小さな括弧

$drc_embed_vine='<iframe src="https://vine.co/v/$2/embed/'.(($vbulletin->options['drc_embed_vine_smpl'])?'simple':'postcard')). width="480" height="480" frameborder="0">'; 
関連する問題