index.php:
$smarty = new Smarty;
$smarty->assign('Contacts',
array('555-222-9876',
'zaphod@slartibartfast.com',
array('555-444-3333',
'555-111-1234')));
$smarty->display('index.tpl');
index.tpl:
{$Contacts[0]}<br>
{$Contacts[1]}<br>
{* you can print arrays of arrays as well *}
{$Contacts[2][0]}<br>
{$Contacts[2][1]}<br>
OUTPUT:
555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
555-111-1234<br>
Smarty 模板 -- 从php分配的变量
最新推荐文章于 2025-12-02 09:17:36 发布
本文通过一个具体的示例展示了如何使用Smarty模板引擎来处理并显示数组数据。Smarty是一种广泛使用的PHP模板引擎,它允许开发者将业务逻辑与表现层分离,提高了开发效率和代码的可维护性。示例中包含了多维数组的赋值与展示。
5305

被折叠的 条评论
为什么被折叠?



