简体   繁体   English

存储值并检查值是否为空

[英]Storing value and checking if the value is empty

Is there a way I can check if the value of 有没有一种方法可以检查值

<?php the_field('max_working_height')?> 

is empty or store the value that will be displayed when I use acnd check if that is empty or not. 为空或存储将在我使用acnd检查是否为空时显示的值。 If the value is not empty then I have to make it execute a set of html code and php code like this 如果该值不为空,那么我必须使其执行一组这样的html代码和php代码

    <tr style="height: 25px; margin-left: 10px;">
<td style="margin-left: 10px;"><b>Max
  <?php the_field('max._outreach'); ?></td> 
</tr>

Please help. 请帮忙。

<?php
$maxWorkingHeight = the_field('max_working_height');

if (false == $maxWorkingHeight) {
    // print your html/php
} else {
    // you can print $maxWorkingHeight here if you need it
}

That assumes that your function returns a falsy value if the field isn't set ( null , false , 0 , or an empty string are all examples of falsy values in PHP). 假设如果未设置字段( nullfalse0或空字符串都是PHP中falsy值的示例),则函数返回falsy值。

If, as it appears, you are using the ACF plugin, then the_field() echos out the value of the field. 如果显示出您正在使用ACF插件,则the_field()回显该字段的值。 If you want to capture the value of the field, use get_field() . 如果要捕获字段的值,请使用get_field() Check out the docs here . 此处查看文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM