Re: [SMARTY] count element of array ?

From: Date: Thu, 08 Apr 2004 07:44:18 +0000
Subject: Re: [SMARTY] count element of array ?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11249@lists.php.net to get a copy of this message
adwinwijaya wrote:
I need that to formating the string ... for example I have an array contain {'a','b','c','d'} and I want to print it as a,b,c,d (with ',') but after d .. it doesnt need to add ',' ..
Try this plugin: <?php /* Join array elements with a string * * Params:
*    array    - an array
*    glue    - string to join elements
*/ function smarty_compiler_implode($tag_attrs, &$compiler) { $_params = $compiler->_parse_attrs($tag_attrs); if (!isset($_params['array'])) {
       $compiler->_syntax_error("assign: missing 'array' parameter", E_USER_WARNING);
       return;
} if (!isset($_params['glue'])) {
       $compiler->_syntax_error("assign: missing 'glue' parameter", E_USER_WARNING);
       return;
} return "echo implode({$_params['array']}, {$_params['glue']});"; } ?> Example: {implode array=$your_array_name glue=','} -- Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk> Web Developer & Database Admin Cromwell Tools Ltd. Leicester, England.

« previous php.smarty.general (#11249) next »