Html 如果变量为Null,如何隐藏DIV

Html 如果变量为Null,如何隐藏DIV,html,css,variables,display,Html,Css,Variables,Display,我有一个div和一个变量,如果变量为空,我想隐藏这个div。有什么线索吗?例如: <div class='h-box'> <h1>text<h1/> <p><?php echo regular_he(); ?><p/> </div> 文本 您可以使用PHP检查它是否为空is\u empty函数: <?php if(is_empty($var_to_check)): ?> <div cl

我有一个div和一个变量,如果变量为空,我想隐藏这个div。有什么线索吗?例如:

<div class='h-box'>
<h1>text<h1/>
<p><?php echo regular_he(); ?><p/>
</div>

文本


您可以使用PHP检查它是否为空
is\u empty
函数:

<?php if(is_empty($var_to_check)): ?>
  <div class='h-box'>
    <h1>text<h1/>
    <p><?php echo regular_he(); ?><p/>
  </div>
<?php endif; ?>

文本


请参阅文档:

只有当变量为空或null时,才可以通过检查变量

if($var == "" && $var == NULL){
  // Do your work
}   
对于数组

if(!empty($array_name)){
  // Do your work
}
举个例子

<?php
    $name = "Akash";
    $test_array = [];
    function regular_he(){
         return "Something";
    }
?>
 <!-- For Variable -->
<?php if($name != "" && $name != NULL): ?>
    <div class='h-box'>
        <h1>text<h1/>
        <p><?php echo regular_he(); ?><p/>
    </div>
<?php endif; ?>


<!-- For Array -->
<?php if(!empty($test_array)): ?>
    <div class='h-box'>
        <h1>text<h1/>
        <p><?php echo regular_he(); ?><p/>
    </div>
<?php endif; ?>

文本

文本


这里的答案非常简单。它显示了如何在两行代码中隐藏和显示div。

这条规则是什么,它是什么returns@ManiruzzamanAkash这就是变量(或者这叫做数组?我不熟悉这个)。我有一些。其中一些包含文本,一些包含指向音频文件的链接。