如果为空,则删除一些 UL

Delete some UL if empty

现在我的输出是这样的

我想删除空列表

刚刚尝试将此代码清空或设置在列表项中

<?php if(isset($page)): //but i got different output   ?>

甚至像

<?php if(empty($page): //but i got an error    ?>

这是我的 运行 代码,没有 if 语句

<?php 
$letter='A';
for($i= 1; $i <=26 ;$i++,$letter++):?>
<?php 

    $pages = $db->prepare("
    SELECT * FROM pages WHERE LEFT(`title`, 1) = '".$letter."'

    ");
    //$check =$db->query("SELECT * FROM watch WHERE animelist_id=".$page['id']." and acc_id=".$_SESSION["user_id"]."");
    $pages->bindParam(1,$letter, PDO::PARAM_STR);
    $pages->execute();
?>

<div class = "listitems">

    <?php echo '<h5>'.$letter.'</h5>';?>
            <?php foreach($pages as $page): ?>

                        <ul>
                            <li>
                            <a href="<?php echo BASE_URL;?>/page.php?page=<?php echo e($page['slug']);?>"><?php echo e($page['label']);?></a>

                            </li>
                        </ul>



            <?php endforeach; ?>

</div>
<?php endfor; ?>

isset()

it returns true only when the variable is not null.
for a empty array, it return true.

空()

Determine whether a variable is empty.
for a empty array, it return true.

所以你应该使用:

if(!empty(pages))