我有一个数组:
$team_details = Array ( [id] => 1 [name] => doge_finder [total_rewards] => 52.00524500 [desciption] => team is only of doge miners [created_by] => 20 );
/* assigning to a smarty template */
$smarty->assign("team_record", $team_details);
$smarty->display($tpl);
在模板文件中:
{foreach from= $team_record key=team item=trecord}
{$trecord[$key].name}
{/foreach}
在结果输出中必须是“doge_finder”,但我得到了数组中每条记录的第一个初始字符,即。 “1 d 5 t 2”
我该如何解决这个问题?
最佳答案
我们可以使用{$team_record|print_r}
来显示smarty文件中的整个数组。
输出:
Array
(
[id] => 1
[name] => doge_finder
[total_rewards] => 52.00524500
[desciption] => team is only of doge miners
[created_by] => 20
)
我们可以使用下面的代码迭代Smarty文件中的数组
{foreach from=$team_record key=arrayIndex item=trecord}
{$arrayIndex}: {$trecord}
<br>
{/foreach}
输出:
id: 1
name: doge_finder
total_rewards: 52.00524500
desciption: team is only of doge miners
created_by: 20
关于php - 如何在smarty中打印数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679384/