Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何访问smarty模板中的多维数组元素?_Php_Arrays_Multidimensional Array_Smarty_Associative Array - Fatal编程技术网

Php 如何访问smarty模板中的多维数组元素?

Php 如何访问smarty模板中的多维数组元素?,php,arrays,multidimensional-array,smarty,associative-array,Php,Arrays,Multidimensional Array,Smarty,Associative Array,我将从PHP向smarty分配一个名为$user_details的多维数组,如下所示: $smarty->assign('user_details', $user_details); 实际数组$user\u details如下所示: Array ( [user_id] => 263129476e186da1dc28c8d0b5e48521 [user_first_name] => Nishant [user_last_name] => Dey

我将从PHP向smarty分配一个名为$user_details的多维数组,如下所示:

$smarty->assign('user_details', $user_details);
实际数组$user\u details如下所示:

Array
(
    [user_id] => 263129476e186da1dc28c8d0b5e48521
    [user_first_name] => Nishant
    [user_last_name] => Dey
    [user_name] => agridipankar@in.com
    [user_password] => 1994nishant
    [user_email] => agridipankar@in.com
    [user_dob] => 
    [user_subscription] => lifetime
    [user_reg_date] => 18/09/2012 04:09:11 pm
    [user_last_login] => 1351274390
    [user_last_logged_in] => 26/10/2012 11:29:50 pm
    [user_mobile_number] => 9436525368
    [assigned_tests_data] => Array
        (
            [0] => Array
                (
                    [test_name] => JEE XI Test : Mathematics Full Syllabus 2
                    [test_no_questions] => 100
                    [test_max_score] => 400.000
                    [test_duration] => 7200
                )

            [1] => Array
                (
                    [test_name] => JEE XI Test : Mathematics Full Syllabus 1
                    [test_no_questions] => 100
                    [test_max_score] => 400.000
                    [test_duration] => 7200
                )

            [2] => Array
                (
                    [test_name] => JEE XI Test : Probability
                    [test_no_questions] => 50
                    [test_max_score] => 200.000
                    [test_duration] => 3600
                )

            [3] => Array
                (
                    [test_name] => JEE XI Testlet : Probability 2
                    [test_no_questions] => 15
                    [test_max_score] => 60.000
                    [test_duration] => 1200
                )

            [4] => Array
                (
                    [test_name] => JEE XI Testlet : Probability 1
                    [test_no_questions] => 15
                    [test_max_score] => 60.000
                    [test_duration] => 1200
                )
)
)
现在要在smarty模板中打印数组,我执行了以下代码,但无法打印内部数组值。你能告诉我哪里出了问题吗?提前谢谢

{section name=users loop=$user_details}
      <table width="100%"  class="base-table tbl-practice" cellspacing="0" cellpadding="0" border="0">
        <thead> 
          <tr>
            <th width="40%" class="sorter-false" style="text-align:center;">Test Name</th>
            <th width="20%" class="sorter-false" style="text-align:center;">No. of Questions</th>
            <th width="20%" class="sorter-false" style="text-align:center;">Total Marks</th>
            <th width="20%" class="sorter-false" style="text-align:center;">Duration</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td valign="top">{$user_details[users].[assigned_tests_data].test_name}</td>
            <td align="center" valign="top">{$user_details[users].[assigned_tests_data].test_no_questions}</td>
            <td align="center" valign="top">{$user_details[users].[assigned_tests_data].test_max_score}</td>
            <td align="center" valign="top">{$user_details[users].[assigned_tests_data].test_duration}&nbsp;Hrs</td>

          </tr>   
            {/section}
{section name=users循环=$user\u details}
测试名称
问题数目
总分
期间
{$user\u details[users].[assigned\u tests\u data].test\u name}
{$user\u details[users].[assigned\u tests\u data]。test\u no\u questions}
{$user\u details[users].[assigned\u tests\u data].test\u max\u score}
{$user\u details[users].[assigned\u tests\u data].测试持续时间}小时
{/section}

我建议您使用两个smarty“foreach”语句,而不是一个节。比如说

{foreach from=$user_details item=users}
<table width="100%"  class="base-table tbl-practice" cellspacing="0" cellpadding="0" border="0">
    <thead> 
      <tr>
        <th width="40%" class="sorter-false" style="text-align:center;">Test Name</th>
        <th width="20%" class="sorter-false" style="text-align:center;">No. of Questions</th>
        <th width="20%" class="sorter-false" style="text-align:center;">Total Marks</th>
        <th width="20%" class="sorter-false" style="text-align:center;">Duration</th>
      </tr>
    </thead>
    <tbody>
   <tr>
  {foreach item=$users.assigned_tests_data item=atd}
    <td valign="top">{$atd.test_name}</td>
    <td align="center" valign="top">{$atd.test_no_questions}</td>
    <td align="center" valign="top">{$atd.test_max_score}</td>
    <td align="center" valign="top">{$atd.test_duration}&nbsp;Hrs</td>        
  {/foreach}
  </tr>
{/foreach}
{foreach from=$user\u details item=users}
测试名称
问题数目
总分
期间
{foreach item=$users.assigned_tests_data item=atd}
{$atd.test_name}
{$atd.test_no_questions}
{$atd.test_max_score}
{$atd.测试持续时间}小时
{/foreach}
{/foreach}

希望这有帮助。

这将用于访问内部数组键元素和包含它的子任务数组

<table width="100%"  class="base-table" cellspacing="0" cellpadding="0" border="0" id="users_test_listing">
        <thead> 
          <tr>
            <th width="40%" class="sorter-false" style="text-align:center;">Test Name</th>
            <th width="20%" class="sorter-false" style="text-align:center;">No. of Questions</th>
            <th width="20%" class="sorter-false" style="text-align:center;">Total Marks</th>
            <th width="20%" class="sorter-false" style="text-align:center;">Duration</th>
          </tr>
        </thead>
        <tbody> 
          {foreach from=$user_details.assigned_tests_data item=test_data}
          <tr>
            <td valign="top">{$test_data.test_name}</td>
            <td align="center" valign="top">{$test_data.test_no_questions}</td>
            <td align="center" valign="top">{$test_data.Marks}</td>
            <td align="center" valign="top">{$test_data.Time}&nbsp;Hrs</td>
          </tr>   
          {/foreach}
        </tbody>
      </table>

测试名称
问题数目
总分
期间
{foreach from=$user\u details.assigned\u tests\u data item=test\u data}
{$test\u data.test\u name}
{$test_data.test_no_questions}
{$test_data.Marks}
{$test_data.Time}小时
{/foreach}