> Smarty模板引擎中文在线手册 > 13. Methods [方法]

append 添加
append_by_ref 引用添加
assign 赋值
assign_by_ref 引用赋值
clear_all_assign 清除所有赋值
clear_all_cache 清除所有缓存
clear_assign 清除赋值
clear_cache 清除缓存
clear_compiled_tpl 清除已编译模板
clear_config 清除配置
config_load 加载配置
display 显示
fetch 取得输出的内容
get_config_vars 取配置变量的值
get_registered_object 取得已注册的对象
get_template_vars 取得模板变量的值
is_cached 是否已被缓存
load_filter 加载过滤器
register_block 注册一个块
register_compiler_function 注册编译函数
register_function 注册函数
register_modifier 注册修饰器
register_object 注册对象
register_outputfilter 注册输出过滤器
register_postfilter 注册提交过滤器
register_prefilter 注册预过滤器
register_resource 注册资源
trigger_error 触发错误
template_exists 模板是否存在
unregister_block 注销一个块
unregister_compiler_function 注销编译函数
unregister_function 注销函数
unregister_modifier 注销修饰器
unregister_object 注销对象
unregister_outputfilter 注销输出过滤器
unregister_postfilter 注销提交过滤器
unregister_prefilter 注销预过滤器
unregister_resource 注销资源

append 添加

void append (mixed var)

void append (string varname, mixed var)

void append (string varname, mixed var, boolean merge)

This is used to append an element to an assigned array. If you append to a string value, it is converted to an array value and then appended to. You can explicitly pass name/value pairs, or associative arrays containing the name/value pairs. If you pass the optional third parameter of true, the value will be merged with the current array instead of appended.

添加指定的元素到数组中。如果是添加一个字符串,该字符串会被转换为数组格式后再进行添加。所添加的数据可以采用 名称, 数值 的格式,或者是使用 “=>”连接的联合数组格式。如果第三个可选参数被指定为 TRUE,所添加的数据会和数组中现有数据进行合并,而不是直接添加。

Technical Note: The merge parameter respects array keys, so if you merge two numerically indexed arrays, they may overwrite each other or result in non-sequential keys. This is unlike the array_merge() function of PHP which wipes out numerical keys and renumbers them.

注意:使用第三个参数“merge”时要考虑到数组的索 引,所以,如果添加和被添加的数组都是以数字为索引,他们会互相覆盖,或者产生不连续的索引。这并不象PHP中的array_merge()函数,后者会 删除原有的数字索引,重新对索引进行编号。

Example 13-1. append 例子 13-1. 添加

// passing name/value pairs 以 名称,数值 的方式添加
$smarty->append("Name","Fred");
$smarty->append("Address",$address);

// passing an associative array 以联合数组的方式添加
$smarty->append(array("city" => "Lincoln","state" => "Nebraska"));
上一篇:
下一篇: