gpt4 book ai didi

关联阵列上的 Smarty 电流

转载 作者:行者123 更新时间:2023-12-03 23:27:45 25 4
gpt4 key购买 nike

我有一个关联数组,我正在尝试使用 smarty 获取第一条记录。

在 php 中,我使用 current(array),但 smarty 似乎没有电流。

所以我写了下面的代码

{if is_array($browseProducts.data) }
<ul class="products-grid">

{foreach from=$browseProducts.data item=item}
{assign var='image' value=''}
{if is_array($item.images) }
{php} $image=current($item.images); {/php}
{/if}
{/foreach}

</ul>
{/if}

在 {php} 部分 current($item.images) 给出警告:current() [function.current]:传递的变量不是数组或对象

语法是正确的,所以我猜来自 smarty 的 $item.images 不能被 {php} 读取

任何方式将 $item.images 传递给 {php} 部分,或者什么。

有什么建议可以解决我的问题吗?

最佳答案

但是如果数组的键是关联的呢?你也可以这样做:

{$item.images|@current}

关于关联阵列上的 Smarty 电流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3861440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com