<!--{foreach from=$goodsattr item=attr}-->
       {if $goodscat && $goodscat eq $attr}
           相等
       {else}
        1是{$goodscat}<br>
         2是{$attr}<br>;
       {/if}
       <!--{/foreach}--> 如果$goodscat有值,并且是$goodsattr数组里面的一个...
为什么在循环中它就是不能打印出来相等呢...
我觉着电脑说我就是不相等,我快气疯了...
请高人指点

解决方案 »

  1.   

    {if $goodscat and ($goodscat eq $attr) } 这样看看。
      

  2.   

    到底用的是{}
    还是<!--{}--><!--{foreach from=$goodsattr item=attr}-->
          <!--{if $goodscat && $goodscat eq $attr}-->
              相等
          <!--{else}-->
            1是<!--{$goodscat}--> <br>
            2是<!--{$attr}--> <br>;
          <!--{/if}-->
          <!--{/foreach}--> 
      

  3.   

    把 $goodsattr ,$goodscat 值贴上来看看。
      

  4.   

    $goodsattr
    我print_r的结果
    Array ( [0] => HP [1] => APSON [2] => CANON [3] => LEXMARK [4] => LENOVO [5] => SAMSUNG ) 
    $goodscat = APSON
      

  5.   

    <!--{if $goodscat && $goodscat eq $attr}-->
              相等
          <!--{else}-->
            1是<!--{$goodscat}--> <br>
            2是<!--{$attr}--> <br>;
          <!--{/if}--> 
      

  6.   

    我测试的.不过我用的<{ }>
    代码区
    <?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>