Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

count of array; if condition

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bingomanatee
Smarty n00b


Joined: 25 Feb 2006
Posts: 1

PostPosted: Tue Dec 19, 2006 12:44 am    Post subject: count of array; if condition Reply with quote

I want a block of code to execute ONLY if an array has contents; how can I test to find out how many elements are in an array within Smarty (or more generally, find an array count within smarty)?
Back to top
View user's profile Send private message Visit poster's website
Hielke Hoeve
Smarty Elite


Joined: 06 Jan 2006
Posts: 406
Location: Netherlands

PostPosted: Tue Dec 19, 2006 12:30 pm    Post subject: Reply with quote

use count() -> http://uk.php.net/manual/function.count.php
or isset() -> http://uk.php.net/manual/en/function.isset.php
or empty() -> http://uk.php.net/manual/en/function.empty.php
_________________
Debug XHTML Compliance
SmartyPaginate
Smarty License Questions
---
(About Unix) The learning curve is full of aha! moments, such as that glorious day that the full beauty of grep and, later, find is revealed in all its majesty. --- Robert Uhl <ruhl@4dv.net>
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 19, 2006 3:25 pm    Post subject: Reply with quote

Code:
{if !empty($myarray)}...{/if}

Code:
{if $myarray|@count gt 0}...{/if}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP