Appending array(s) to a template var
| From: | Joscha Feth | Date: | Wed, 19 Feb 2003 17:59:03 +0000 |
| Subject: | Appending array(s) to a template var | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7912@lists.php.net to get a copy of this message | ||
Hi,
I made two functions for this (it saves some foreach-loops and should
therefore increase performance)
/**
* appends an array with its keys onto a template var
*
* @param string $tpl_var_name the template variable name
* @param mixed $array the array to append
*/
function append_array($tpl_var_name, $array)
{
$this->_tpl_vars[$tpl_var_name] =
array_merge($this->_tpl_vars[$tpl_var_name],$array);
settype($this->_tpl_vars[$tpl_var_name],'array');
}
/**
* appends an array with its keys onto a template var by reference
*
* @param string $tpl_var_name the template variable name
* @param mixed $array the array to append
*/
function append_array_by_ref($tpl_var_name, &$array)
{
foreach($array AS $key=>$val) {
$this->_tpl_vars[$tpl_var_name][$key] =
&$array[$key];
}
settype($this->_tpl_vars[$tpl_var_name],'array');
}
Greets,
Joscha