我将一个名为 $user_details 的多维数组从 PHP 分配给 smarty,如下所示:
$smarty->assign('user_details', $user_details);
实际的数组$user_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} Hrs</td>
</tr>
{/section}