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 } ?>
My code looks like this:
<?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 } ?>
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.
Here's my answer that seems to be going a totally different route than everyone else, which i have no idea why.
To do what OP wants, one way is to expand the php tag to include all.
You can make use if
empty()
function:or
hiding something is pretty easy in php you can use it in several ways and here is how it would look like
The
isset()
function checks if the variable has been set, even if to an empty string. There's theempty()
function which checks if the variable is not set or set to empty string.