首页 > 解决方案 > 如果没有为该选项卡提供数据,则使用 PHP 删除选项卡

问题描述

这里我有一个标签系统,但其中一个标签 ($live_counties) 没有数据 ($location['area_name'])。

如果该选项卡中没有数据,我将如何删除该选项卡?

谢谢

一个新手:\

    <div class="locations-by-type max max-900" style="z-index:-1">

        <div style="text-align: center; margin: 30px 0">
            FITER BY:
            <?php
            $live_locations = get_field('coming_soon_areas');
            $live_location = array_unique(array_column($live_locations, 'area_county'));
            if ($live_location) {
                echo '<span class="unique-area-county active">ALL</span>&nbsp; |';
                $i = 0;
                foreach ($live_location as $live_counties) { $i ++;
                    
                    echo '<span class="unique-area-county">'.$live_counties.'</span>';

                    if ($i < count($live_location)) {
                        echo '<span class="unique-area-divider">|</span>';
                    }
                }
            }?>
        </div>

        <?php
        foreach( $locations as $location_type=>$location_areas ){?>
        
            <div class="max max-700 location-type locations-<?=$location_type?> <?php if(( 'live' == $location_type ) && (!isset($_GET['coming-soon']))){ ?>active<?php } ?> ">
    
                <div class="location-flex">
                <?php
                if( $location_areas ){
                    foreach( $location_areas as $location ){?>
                        <div class="location active" data-county="<?= strtoupper($location['area_county']); ?>">
                            <p class="name">
                                <span><?=$location['area_name']?></span>
                            </p>
                        </div>
                    <?php
                    }
                }?>
                </div>
            </div>
        <?php } ?>
        <div style="text-align: center">
            <button type="button" class="btn yellow btn-check btn-coverage">Check Your Coverage</button>
        </div>
    </div>

标签: php

解决方案


如果您只想跳过该迭代并继续下一个,您可以测试条件并使用continue

if( $location_areas ){
     foreach( $location_areas as $location ){
        if (!$location['area_name'] || trim($location['area_name']) === '') continue; // this will end this iteration of the loop and move on to the next one
?>

推荐阅读