Smarty in_array值

时间:2013-01-18 13:57:18

标签: 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打印他(阵列没有序列化,我已经为你的сonveniece做了)

{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}

3 个答案:

答案 0 :(得分:15)

你可以用这个:

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

答案 1 :(得分:3)

你的意思是这样吗?

{if $aNotice.sCode == '05'} ....

答案 2 :(得分:0)

谢谢你 hek2mgl Jeff Bic ,修改了你的答案,这很好用:

{if !$aSegment.aNotices.aStop|@count gt 0}
    {t lang='en'}Stop duration{/t}{if $server.lang != 'en'} / {t}Stop duration{/t}{/if}: {$aSector.aStops.$iSegmentIndex|mins_to_time}
{/if}