Joomla PHP Template Logic I'm in the process of building some templates for Joomla, and although it all works as desired, I can't help thinking that there has to be a more elegant way to do this in PHP than my current approach. For the record, I'm still reasonably new to PHP!

Using collapsible module positions, I need to assign various CSS classes to a div depending on how many modules are published on a particular row. The code I wrote is below;

    if (($footer1 != "0") &amp;&amp; ($footer2 == "0") &amp;&amp; ($footer3 == "0")) {
    $footerWidth = 'full';
    }
    elseif (($footer1 == "0") &amp;&amp; ($footer2 != "0") &amp;&amp; ($footer3 == "0")) {
    $footerWidth = 'full';
    }
    elseif (($footer1 == "0") &amp;&amp; ($footer2 == "0") &amp;&amp; ($footer3 != "0")) {
    $footerWidth = 'full';
    }
    elseif (($footer1 != "0") &amp;&amp; ($footer2 != "0") &amp;&amp; ($footer3 == "0")) {
    $footerWidth = 'one_half';
    }
    elseif (($footer1 != "0") &amp;&amp; ($footer2 == "0") &amp;&amp; ($footer3 != "0")) {
    $footerWidth = 'one_half';
    }
    elseif (($footer1 == "0") &amp;&amp; ($footer2 != "0") &amp;&amp; ($footer3 != "0")) {
    $footerWidth = 'one_half';
    }
    else {
    $footerWidth = 'one_third';
    }


I then use the following code in the template itself to check for modules published;

    &lt;?php if ($footer1 &gt; 0) : ?&gt;
                &lt;div class="&lt;?php echo htmlspecialchars($footerWidth); ?&gt;"&gt;
                    &lt;jdoc:include type="modules" name="footer1" style="html5" /&gt;
                &lt;/div&gt;
    &lt;?php endif; ?&gt;
    &lt;?php if ($footer2 &gt; 0) : ?&gt;
                &lt;div class="&lt;?php echo htmlspecialchars($footerWidth); ?&gt;"&gt;
                    &lt;jdoc:include type="modules" name="footer2" style="html5" /&gt;
                &lt;/div&gt;
    &lt;?php endif; ?&gt;
    &lt;?php if ($footer3 &gt; 0) : ?&gt;
                &lt;div class="&lt;?php echo htmlspecialchars($footerWidth); ?&gt;"&gt;
                    &lt;jdoc:include type="modules" name="footer3" style="html5" /&gt;
                &lt;/div&gt;
    &lt;?php endif; ?&gt;


Can anyone suggest / recommend a better approach? It just seems like a lot of code for a simple function.
Something somewhat confusing is the comparison to of each $footer# to the string '0' then later comparing it to greater than integer 0.  This is practically the definition of weakly typed languages.  If you know what $footer# variables actually contain you might be able to simplify this, but here is a fully functioning replacement to the first code block.

One could simplify this a bit, but the core concepts are there.  '0' casts to False, and True casts to 1.  There are plenty of other ways to accomplish the same thing, especially if you have significantly more incoming $footer#'s, or if they are stored in something iteratable like an array.  

//$footer1 = '10';
//$footer2 = '-5';
//$footer3 = '0';

$footer1Bool = (bool) $footer1;
$footer2Bool = (bool) $footer2;
$footer3Bool = (bool) $footer3;

$footer1Int = (int) $footer1Bool;
$footer2Int = (int) $footer2Bool;
$footer3Int = (int) $footer3Bool;

$footerCombined = $footer1Int + $footer2Int + $footer3Int;

if ( $footerCombined &gt;= 3 ) {
    $footerWidth = 'one_third';
} else if ( $footerCombined == 2 ) {
    $footerWidth = 'one_half';
} else {
    $footerWidth = 'full';
}