If the array is not null (and has values in it), then I want to display the table.
But if it is null, then I don’t want to display any table code at all.
Using an MVC framework which appends a footer to the page.
What is the best way to avoid a statement like:
<?php
if ($users) {
echo '<table id="tha_table" cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>';
} ?>
And, don’t want to do another test to add the table footer.
I always use empty() to check whether an array is empty. Empty will also check whether the variable is null. Note that empty() does not throw a warning if the array variable is not set, which may or may not be desirable.