Re: [SMARTY] Count array function/modifier -- does it exist?
| From: | Monte Ohrt | Date: | Fri, 26 Jul 2002 13:21:27 +0000 |
| Subject: | Re: [SMARTY] Count array function/modifier -- does it exist? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5463@lists.php.net to get a copy of this message | ||
This function is not necessary, you might want to remove it and add this to the FAQ or something.
{$array|@count} does the same thing, and "@" can be applied it to any modifier.
Monte
Simon Willison wrote:
At 07:14 26/07/2002 +0700, Hendy Irawan wrote:-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.Hi all in smarty-general, I wonder whether a template function/modifier is available to count the number of items in an array. There modifiers to count words, paragraphs, etc. but to count arrays??? (yes, just a simple call to count($whaterever);) Thank you.Here's a quick plugin that should do what you want. Just save it as modifier.count_array.php in your Smarty plugins directory, then use {$array|count_array} to call it. I've added it to the Smarty Wiki as well: http://smarty.incutio.com/?page=SmartyPlugins Cheers, Simon Willison ==== <?php /* * Smarty plugin * -------------------------------------------------------------* Type: modifier * Name: count_array* Purpose: count the number of elements in an array * ------------------------------------------------------------- */ function smarty_modifier_count_array($array) {if (is_array($array)) { return count($array); } else { return 0; }} ?>