我已经尝试了几个小时,如果只是 PHP,我现在就可以完成了,但这需要 Smarty 3,所以事情有点不同。我很难从数组中获取特定的复数键。数组看起来像这样
Array
(
[0] => Array
(
[id] => 1
[client] => Jane Doe
[email] => jane@doe.com
)
[1] => Array
(
[id] => 2
[client] => John Doe
[email] => john@doe.com
)
[2] => Array
(
[id] => 3
[client] => Jim Doe
[email] => jim@doe.com
)
我可以使用 PHP 访问它就好了,Smarty 让我绊倒了,文件是两个
- 客户端.php
- clients.tpl <- smarty
我在 .php 文件中分配了以下数组
$totalEntries = $results['products']['product'];
$ca->assign('innerArray', $totalEntries);
这$results['products']['product']
是输出上面看到的数组的内容。
现在在.tpl文件中,我有以下内容
<select class="form-control" id="sel1">
{foreach $innerArray as $results}
{foreach from=$results.client item=label}
<option value="{$label}">{$label}</option>
{/foreach}
{/foreach}
</select>
这可以输出到下拉列表
- 简·多伊
- 约翰·多伊
- 吉姆·多伊
我得到了正确的部分,我一直在寻找整个互联网来解决这个问题。我的计划是在下拉菜单中引入类似
- 简·多伊 - jane@doe.com
- 约翰·多伊 - john@doe.com
- 吉姆·多伊 - jim@doe.com
但是,当我尝试使用以下内容时,我删除了from=的.client部分
<select class="form-control" id="sel1">
{foreach $innerArray as $results}
{foreach from=$results item=label}
<option value="{$label.client}">{$label.client} - {$label.email}</option>
{/foreach}
{/foreach}
</select>
我遇到了一个看起来像这样的列表
- 1 - 1
- J - J
- j - j
- 2 - 2
- J - J
- j - j
- 3 - 3
- J - J
- j - j
我意识到这基本上是第一个字母和数字,但是我在网上看到各种示例表明我可以从数组中获取我需要的东西,但是当我尝试$label.client - $label.email它不起作用。
我究竟做错了什么?