WordBear WordBear - 7 months ago 15
PHP Question

Indicating an empty array in a PHP switch

The code below displays a table row with one cell, featuring the words "Cultural Symbols," followed by a second, database-generated row (

$SymbolRow3
). How can I modify it so that the first (static) row doesn't display if there's no data in
$SymbolRow3
?

<tr>
<td colspan="3"><strong>Cultural Symbols</strong></td>
</tr>
<?php echo join ($SymbolRow3, ''); ?>


I apparently can't put $SymbolRow3[] inside a switch, so I tried this, without success:

switch($SymbolRow3)
{
case '':
case ' ':
break;
default:
echo '<tr>
<td colspan="3"><strong>Cultural Symbols</strong></td>
</tr>';
break;
}

Answer

you could check for rows in the variable instead of using a switch

<?php
    if (count($SymbolRow3) > 0) {
        echo '<tr>
            <td colspan="3"><strong>Cultural Symbols</strong></td>
        </tr>';
        echo join ($SymbolRow3, ''); ?>
    }
?>