Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty in_array value

Tags:

arrays

php

smarty

I have array like this

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

i am printing him with smarty (array is not serialized, i ve did it for your с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}

how to check with smarty if '05' is exist in aNotices.aStop.sCode ? (before foreach cycle)

Tried this

{if in_array('05', $aSegment.aNotices.aStop)}
    exist
{/if}
like image 860
MyMomSaysIamSpecial Avatar asked Jan 18 '13 13:01

MyMomSaysIamSpecial


2 Answers

you can use this :

{if '05'|in_array:$aSegment.aNotices.aStop}EXIST{/if}
like image 199
Jeff Bic Avatar answered Sep 22 '22 12:09

Jeff Bic


Do you mean something like this?

{if $aNotice.sCode == '05'} ....
like image 36
hek2mgl Avatar answered Sep 19 '22 12:09

hek2mgl