<!--{foreach from=$goodsattr item=attr}-->
{if $goodscat && $goodscat eq $attr}
相等
{else}
1是{$goodscat}<br>
2是{$attr}<br>;
{/if}
<!--{/foreach}--> 如果$goodscat有值,并且是$goodsattr数组里面的一个...
为什么在循环中它就是不能打印出来相等呢...
我觉着电脑说我就是不相等,我快气疯了...
请高人指点
{if $goodscat && $goodscat eq $attr}
相等
{else}
1是{$goodscat}<br>
2是{$attr}<br>;
{/if}
<!--{/foreach}--> 如果$goodscat有值,并且是$goodsattr数组里面的一个...
为什么在循环中它就是不能打印出来相等呢...
我觉着电脑说我就是不相等,我快气疯了...
请高人指点
还是<!--{}--><!--{foreach from=$goodsattr item=attr}-->
<!--{if $goodscat && $goodscat eq $attr}-->
相等
<!--{else}-->
1是<!--{$goodscat}--> <br>
2是<!--{$attr}--> <br>;
<!--{/if}-->
<!--{/foreach}-->
我print_r的结果
Array ( [0] => HP [1] => APSON [2] => CANON [3] => LEXMARK [4] => LENOVO [5] => SAMSUNG )
$goodscat = APSON
相等
<!--{else}-->
1是<!--{$goodscat}--> <br>
2是<!--{$attr}--> <br>;
<!--{/if}-->
代码区
<?php
require_once "inc/smarty.inc.php";
$goodsattr = array ('HP','APSON','CANON','LEXMARK','LENOVO','SAMSUNG');
$goodscat = 'APSON';
$tpl->assign("forum",$goodsattr);
$tpl->assign("goodscat",$goodscat);
$tpl->display("test.tpl");
?>test.tpl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gbk">
<title>测试</title>
</head>
<body>
<{foreach from=$forum item=attr}>
<{if $goodscat && $goodscat eq $attr}>
相等<br/>
<{else}>
1是<{$goodscat}> <br>
2是<{$attr}> <br>
<{/if}>
<{/foreach}>
</body>
<html>