Re: [SMARTY] testing if array has elements
| From: | Andreas Goetz | Date: | Fri, 01 Oct 2004 11:34:07 +0000 |
| Subject: | Re: [SMARTY] testing if array has elements | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11845@lists.php.net to get a copy of this message | ||
Ups. My mistake, sorry. The array way actually semi-empty: Array([0] => )
Had to use
$video[0]['country'] = preg_split('/,\s*/', $video[0]['country'],
-1,
PREG_SPLIT_NO_EMPTY);
to make sure it's really empty...
Thanks,
ANdi
"Andreas Goetz" <cpuidle@gmx.de> wrote in message
news:20041001112416.56144.qmail@pb1.pair.com...
> Not really- it still evaluates to true (always). Compiled template is:
>
> <?php if (count ( $this->_tpl_vars['video']['country'] ) >
> 0): ?>
> <tr><td><b><?php echo
> $this->_tpl_vars['lang']['country']; ?>
> :</b></td>
> <td>
> <?php if (count($_from =
> (array)$this->_tpl_vars['video']['country'])):
> foreach ($_from as $this->_tpl_vars['country']):
> ?>
>
> The last part is produced by the {foreach}, the first count call is from
> {if count($video.country) > 0}
>
> Any ideas?
>
> Thanks,
> Andi
>
> "Thorsten Suckow-Homberg" <ts@siteartwork.de> wrote in message
> news:00ab01c4a7a8$58f063b0$0100a8c0@gandalf...
>> >I need to test if an array has elements, FAQ says to use $array|@count.
>> >Now my array is contained in another one:
>>>{if $video.country|@count}
>>>...output list of countries
>>>{/if}
>>
>> {if count($video.country) != 0}
>> ....
>> {/if}
>>
>> should work just fine....
>>
>> Kind regards
>>
>> Thorsten
>>
>> --
>> What's on a developers mind?
>> http://blog.siteartwork.de