Smarty in_array value

I have an 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 print it using smarty (array is not serializable, I did this for your convenveniece)

{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" exists in aNotices.aStop.sCode? (before the foreach loop)

Tried this

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

      

+3


source to share


3 answers


you can use this:



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

      

+15


source


Do you mean something like this?



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

      

+2


source


Thanks to hek2mgl and Jeff Bic , changed your answers and this works great:

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

      

0


source







All Articles