php - Smarty in_array 值

标签 php arrays smarty

我有这样的数组

{
     "sCode":"05",
     "sCodeName":"critical_tight_connection",
     "iSeverity":1,
     "aData":{
         "iLevelOfDetailt":2,
         "iDuration":35,
         "sLabel":"Labai trumpas pers\u0117dimas, 35 min.",
         "sLink":""
     }
}

我正在用 smarty 打印他(数组未序列化,我这样做是为了您的方便)

{if !empty( $aSegment.aNotices.aStop )}
    <ul>
        {foreach from=$aSegment.aNotices.aStop item=aNotice}
            <li>
                <img class="{$aNotice.sCodeName}" />
                {$aNotice.sLabel}
            </li>
        {/foreach}
    </ul>
{/if}

如果 aNotices.aStop.sCode 中存在 '05',如何使用 smarty 检查? (在 foreach 循环之前)

试过了

{if in_array('05', $aSegment.aNotices.aStop)}
    exist
{/if}

最佳答案

你可以使用这个:

{if '05'|in_array:$aSegment.aNotices.aStop}EXIST{/if}

关于php - Smarty in_array 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14400460/

相关文章:

php - 使用 PHP 从 DOM 节点而不是其子节点获取内容

php - CakePHP Unfilled 单选按钮在提交时更改为不需要的值

Javascript - 追加对象数组

java - 字符串中的表达式到数组列表

jQuery toggle show XHTML Smarty some clahes 也许吗?它不显示

php - 如何从 CS 购物车中的 tpl 文件向 Controller 后端 php 文件发送 ajax 请求?

php - 使用多列的最旧日期时间

PHP多维数组使用for内for来回显字符串

CSS 未在动态 smarty 模板元素上呈现

php - 尝试使用 JSON 但得到 '500 Internal Server Error'