php - 如果没有为该选项卡提供数据,则使用 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> |';
$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>
解决方案
如果您只想跳过该迭代并继续下一个,您可以测试条件并使用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
?>
推荐阅读
- asp.net-core - .NET Core 中的 IFormFile vs byte[] 和文件上传最佳实践
- html - Pug span 无法在 flex div 中正确渲染
- typescript - rxjs 订阅一个类
- node.js - 如何使用 $set 和 filter 方法更新 mongoose 中嵌套数组中的元素?
- powershell - 使用powershell映射进程名和应用程序名
- flutter - Flutter:流和隔离
- python - 目标 WSGI 脚本“/opt/python/current/app/github/wsgi.py”不能作为 Python 模块加载
- c++ - 不能在 C++ 中使用使用状态机模式的对象向量
- reactjs - Next.js onhover Link 组件被刷新
- unity3d - 使用来自多个不同键的玩家输入更改类中的相同布尔值