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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失