admin 发表于 2020-11-22 15:16:09

ThinkPHP,七、使用默认值,当变量未接收到值时,设置默认值


<p class="MsoNormal" align="left"><b><span style="font-size:18.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">使用默认值<span lang="EN-US"><o:p></o:p></span></span></b></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">我们可以给变量输出提供默认值,例如:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{$user.nickname|default="</span><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">这家伙很懒,什么也没留下<span lang="EN-US">"}<o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">对系统变量依然可以支持默认值输出,例如:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{$Think.get.name|default="</span><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">名称为空<span lang="EN-US">"}<o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">默认值和函数可以同时使用,例如:<span lang="EN-US"><o:p></o:p></span></span></p><p>











</p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{$Think.get.name|getName|default="</span><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">名称为空<span lang="EN-US">"}<o:p></o:p></span></span></p>
页: [1]
查看完整版本: ThinkPHP,七、使用默认值,当变量未接收到值时,设置默认值