php - 如何在smarty中打印数组?

标签 php arrays foreach smarty

我有一个数组:

 $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/

相关文章:

PHP、MySQL 选择所有 if

javascript - 在对象数组中搜索对象

java - 你如何传递数组?

c - 如何初始化二维字符数组的内容?

c++ - 为什么C++中的foreach不能遍历第一个元素?

php - Bigcommerce API 更新库存水平(正常库存跟踪和按选项跟踪)

php - 提交表单后重定向是一种好习惯吗?

php - 在 Laravel 5.4 中设置用于测试的内存 SQLite 数据库

c# - foreach 控件 c# 跳过控件

java - 提高 for-each 性能