如何在php中的echo中连接if语句? [英] How to concatenate if statement inside echo in php?

查看:24
本文介绍了如何在php中的echo中连接if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在php中的echo中连接if语句?如何将一些基于条件的 html 附加到 echo 中的 html?类似如下:

Is it possible to concatenate an if statement inside echo in php? How can I attach some condition based html to an html inside an echo? Something like as follow:

<?php
echo '<div class="main">Some html</div>' . if (is_page('my-account')) {
echo '<div class="account_data">Some account related data</div>';
}; . ;
?>

推荐答案

它会对你有所帮助.试试这个.

It will help to you. Try this.

<?php
$html = '';
$html .= '<div class="main">Some html</div>';
 if (is_page('my-account')) {
    $html .= '<div class="account_data">Some account related data</div>';
 }
echo $html;

这篇关于如何在php中的echo中连接if语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆