duanguoyin7008 2012-03-21 20:41
浏览 152
已采纳

Smarty标签PHP isset声明

I am using smarty tags with php and my question / issue is regarding the !isset functionality. To start with, here is how I create and assign my two arrays. Then I use a SMarty IF statement to compare the conditions, and if the conditions are met, either display or do not display the HTML

The first array gets created from the database, is assigned as a Smarty variable.

{section name=cart loop=$cart}
{/section}

The second array is also pulled from the database, but I am assigning this array through Smarty capture:

{capture name='donate' assign='donate'}
{/capture}

Once the arrays are assigned, here is the if statement:

{if $cart[cart].Program == TT && !isset($donate)}
<td>Make a difference. Donate $10.00 to the ASPCA</td>
{/if}

The HTML still will be displayed, even if the $donate array is not set. Appreciate any insight to point out what I may be doing wrong

  • 写回答

2条回答 默认 最新

  • duanmuyao0463 2012-03-22 08:00
    关注
    {capture name='donate' assign='donate'}
    {/capture}
    {$donate|var_dump}
    

    will give you

    string(0) "" 
    

    since only isset(null) === false, you may want to change your expression to

    {if $cart[cart].Program == TT && $donate}
    

    or !empty($donate), if you prefer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog