php - 如何在 smarty 中获取数组的特殊名称的值?
问题描述
我有一个如下的 PHP 数组:
$list = array(
array(
'name'=>'switch',
'value'=>'cisco'
),
array(
'name'=>'switchport',
'value'=>'2'
)
);
如何一步获得name='switch'
or的物品?name='switchport'
因为这是在smarty
模板中,所以有 img
<img src="http://localhost:8080/api.php?switch={$my_need_switch_value}&switchport={$my_need_switchport_value}">
my_need_switch_value
那么,我怎样才能$list
一步到位呢?
解决方案
您可以使用{assign}
来分配新变量。
{foreach from=$list item=customfield}
{if $customfield.name=='switch'}
{assign var=switch value=$customfield.value}
{elseif $customfield.name=='switchport'}
{assign var=portname value=$customfield.value}
{/if}
{/foreach}
然后你可以直接使用$switch
and $switchport
。
推荐阅读
- python - qwidget.setGeometry() 在 linux 上的位置不正确
- javascript - Javascript 中的作用域,使用 let
- javascript - 无法读取未定义的 Vue js 的属性“_router”
- opencart - 如何更改打开购物车中的主页类别和图像
- wordpress - WordPress comment_form() $fields arg 没有生效
- c - 使用 `addrinfo` 结构的内存管理
- regex - 查找具有给定名字的名字
- octobercms - 有没有我可以听的重新排序事件?
- android - 从另一个类访问共享内存
- spring - JSP Spring Maven - 将表单中的数据时间解析到数据库中