paul cappucci
paul cappucci

Reputation: 243

PHP: If empty 2 variables for Drupal

I am working in a Drupal template. I want to know if two variables exist, and if they do not then do or show something else. I know how to do this for only one variable, but what is the correct syntax to look for two? My code is below.

<?php if (!empty($right) && !empty($left)): ?>
    <div id="content-main">
   <?php endif; ?>

I also tried it this way.

<?php if (!empty($right)&&($left)): ?>
    <div id="content-main">
   <?php endif; ?> 

and this way.

<?php if (!isset($right)&&($left)): ?>
    <div id="content-main">
   <?php endif; ?>

None of them work, how do I fix this?

Upvotes: 1

Views: 944

Answers (1)

sab0t
sab0t

Reputation: 137

empty() doesn't check variable initialization, it only checks if it contains a defined set of values that are considered empty ( "", 0, for example).

Your third example is in the right direction, but needs a small tweak:

<?php if (!isset($right)&&!isset($left)): ?>
<div id="content-main">
<?php endif; ?>

The second conditional check after && requires its own isset() as well.

hope this helps.

Upvotes: 1

Related Questions