gpt4 book ai didi

php - 如何在 smarty 模板文件中分配数组?

转载 作者:IT王子 更新时间:2023-10-29 00:58:45 24 4
gpt4 key购买 nike

我想知道是否可以将数组分配给 Smarty 模板文件中的变量?这个我试过了

{assign var='file' value = array('dir','doc','exe')}

但是当我打印出数组时,它会产生这样的结果:

array(\'dir\',\'doc\',\'exe\') 

如何阻止 Smarty 转义数组值?

提前致谢

最佳答案

{php}
$this->assign("array", array('dir','doc','exe'));
{/php}

{foreach from=$array item=item}
{$item}
{/foreach}

Smarty v.3提供了新语法

{$array = ['item1','item2',$item3]}

查看更多详情:http://www.smarty.net/docs/en/language.syntax.variables.tpl

关于php - 如何在 smarty 模板文件中分配数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2244319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com