如何在smarty中使用php变量

如何在smarty中使用php变量,php,smarty,Php,Smarty,嗨,我正在尝试用php为数组编写代码,但没有得到任何解决方案,请帮助我 { 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.

嗨,我正在尝试用php为数组编写代码,但没有得到任何解决方案,请帮助我

{ 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}
{if!in_数组($productgroup.gid,array(69,68,27,31,70,71,72,73,74,75,76,77,{php}echo$cid;{/php}))}
{$productgroup.name}
{/if}

您正在尝试用PHP创建数组吗?然后:

PHP

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

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

还是要在数组中添加动态元素?然后:

PHP

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

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

基本正确。你把变量分配给模板了吗?实际上是变量,我从那个页面上的url获取方法