如果 php 变量为空,如何隐藏几行? [英] How do I hide several lines if php variable is empty?

查看:38
本文介绍了如果 php 变量为空,如何隐藏几行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 PHP 的学习者,如果选择的变量为空,我正在努力隐藏不显示多行.我可以让它在基本级别上工作,但是当要隐藏的内容变得更加复杂时,我就迷失了.我的目标是这样的:

As a learner in PHP, I'm struggling to hide from displaying several lines, if a chosen variable is empty. I can get this to work on a basic level, but am lost when the content to be hidden gets more complicated. The concept I am aiming at is this:

<?php if (isset($g1)) { ?>
((This part should not display if variable $g1 is empty))
<?php } ?>

我的代码如下所示:

<?php if (isset($g1)) { ?>
<a href="img/g1.png"  class="lightbox"  rel="tooltip" data-original-title="<?php print $g1; ?>" data-plugin-options='{"type":"image"}'>
<img class="img-responsive img-rounded wbdr4" src="img/g1.png">
</a>
<?php } ?>

在上面,当变量 g1 为空时工具提示不显示,但其余的会显示.我是新来的,所以我希望我的问题格式正确.感谢帮助.

In the above, the tooltip does not display when variable g1 is empty, but the rest does. I'm new here so, I hope I've formatted my question correctly. Help appreciated.

推荐答案

<?php if (isset($g1) && $g1!='') { ?>
<a href="img/g1.png"  class="lightbox"  rel="tooltip" data-original-title="<?php print $g1; ?>" data-plugin-options='{"type":"image"}'>
<img class="img-responsive img-rounded wbdr4" src="img/g1.png">
</a>
<?php } ?>

这篇关于如果 php 变量为空,如何隐藏几行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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