简体   繁体   中英

How to use php variable in smarty

Hi I am trying to make code for array in php but didn't get any solution please help me

{ if !in_array($productgroup.gid,array(69,68,27,31,70,71,72,73,74,75,76,77,{php}echo $cid;{/php})) }

<option value="{$productgroup.gid}"{if $gid eq $productgroup.gid} selected="selected"{/if}>{$productgroup.name}</option>

{/if}

Are you trying to create array in PHP? Then:

PHP

$smarty->assign('cid', array(69,68,27,31,70,71,72,73,74,75,76,77));

Smarty

{ if !in_array($productgroup.gid, $cid) }
    ...
{/if}


Or you want add dynamic element in your array? Then:

PHP

$smarty->assign('cid', $some_number);

Smarty

{ if !in_array($productgroup.gid,array(69,68,27,31,70,71,72,73,74,75,76,77,$cid)) }
    ...
{/if}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM