echo语句中的IF条件不起作用。
我收到此错误:
语法错误,
中的意外')'
echo ' <div class="panel-body"> '.$dec.' '.(($ttype == "video") ? '<iframe class="embed-responsive-item" width="560" height="315" src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0" allowfullscreen=""></iframe>').' </div>';
答案 0 :(得分:1)
您可以使用变量连接。这将有助于您避免混淆
stock_df = pd.DataFrame({'symbol': ['AAPL', 'AAPL', 'F', 'F', 'F'],
'date': ['2016-1-1', '2016-1-2', '2016-1-1', '2016-1-2', '2016-1-3'],
'price': [100., 101, 50, 47.5, 49]}).set_index(['symbol', 'date'])
>>> stock_df
price
symbol date
AAPL 2016-1-1 100.0
2016-1-2 101.0
F 2016-1-1 50.0
2016-1-2 47.5
2016-1-3 49.0
>>> stock_df.loc['AAPL']
price
date
2016-1-1 100
2016-1-2 101
>>> stock_df.loc['AAPL', '2016-1-2']
price 101
Name: (AAPL, 2016-1-2), dtype: float64
答案 1 :(得分:1)
让你的生活变得轻松,并使用:
<div class="panel-body">
<?php echo $dec; ?>
<?php
(($ttype == "video") ? '<iframe class="embed-responsive-item" width="560" height="315"
src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0" allowfullscreen=""></iframe>' : '');
?>
</div>
在您的代码中,您缺少Ternary运算符的else条件。
使用您的代码解决方案:
echo '
<div class="panel-body">'.$dec.'
'.(($ttype == "video") ? '
<iframe class="embed-responsive-item" width="560" height="315"
src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0" allowfullscreen="">
</iframe>' : '').
'</div>';