Testing if an array is empty?
| From: | gawan | Date: | Tue, 10 Dec 2002 22:59:12 +0000 |
| Subject: | Testing if an array is empty? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6722@lists.php.net to get a copy of this message | ||
I have a table row with two columns. The left column has a static html
header "Authors" and the right one contains a smarty section loop to output
author names fetched from a database as a smarty array variable.
How can I test if there are any elements in the authors array (or any smarty
array variable)? {if $authors != ''}{/if} or similar structures don't work.
I need kind of a {if $array is empty}structure
I mean not to print this html row at all if section loop will print nothing.
I cant use smarty.section.name.total as I have to test it before the loop to
get rid off the static header.
{if $sisbn not empty} // this is what I would need, but is illegal
<tr>
<td bgcolor="#FFFFEE">Authors</td>
<td bgcolor="#FFFFEE">
{section name=id loop=$sisbn}
{$authors[id]}{if not $smarty.section.id.last} ;{/if}
{/section}
</td>
</tr>
{/if}