首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP:如何删除没有任何解决方案的组?

PHP:如何删除没有任何解决方案的组?
EN

Stack Overflow用户
提问于 2018-06-15 01:21:51
回答 1查看 0关注 0票数 0

我不知道PHP,我想在PHP中实现一个解决方案,而不是通过JS来输出没有解决方案的行标题。

产出:

代码语言:txt
复制
    <table class="rls">

<tr class="res_g_0">
    <td class="res-type">
        <h3>Wide 16:10 (5K, 4K, HD):</h3>
    </td>
    <td>
        <ul class="list-inline">
            <li class="res_1280x800">
                <a href=""><strong>1280x800</strong></a>
            </li>
            <li class="res_1440x900">
                <a href=""><strong>1440x900</strong></a>
            </li>
        </ul>
    </td>
</tr>

<!--The class="res_g_1" is generated, but don't have any available resolutions. I remove it from DOM with JS from below."-->
<tr class="res_g_1">
    <td class="res-type">
        <h3>Mobile (iPhone X):</h3>
    </td>
    <td>
        <ul class="list-inline">
        </ul>
        <div data-target=".res_g_1" class="not_found_res"></div>
    </td>
</tr>
<!--The end of a group resolution without resolutions"-->

<tr class="res_g_2">
    <td class="res-type">
        <h3>Mobile (Android):</h3>
    </td>
    <td>
        <ul class="list-inline">
            <li class="res_480x854">
                <a href=""><strong>480x854</strong></a>
            </li>
            <li class="res_1080x1920">
                <a href=""><strong>1080x1920 HD</strong></a>
            </li>
        </ul>
    </td>
</tr>

代码语言:txt
复制
<script>
var resolution_list = {
        init: function () {
            if ($('.not_found_res').length) {
                $('.not_found_res').each(function () {
                    $($(this).data('target')).remove();
                })
            }
        }
    }
   resolution_list.init();
</script>

下面的代码正在生成上面的HTML代码:(在这里,我想在PHP中放置一个if语句或任何东西来不输出没有任何分辨率的决议组)

代码语言:txt
复制
            <table class="rls">
        <?php $i = 0; ?>
        <?php foreach ($resolutions as $type => $group) { ?>
        <tr class="res_g_<?= $i ?>">
            <td class="res-type">
                <h3><?=$type?>:</h3>
            </td>
            <td>
                <ul class="list-inline">
                <?php $found = false; ?>
                <?php foreach ($group as $res) { ?>
                <?php if ($res->resolution_width > $wallpaper->wallpaper_width || $res->resolution_height > $wallpaper->wallpaper_height) continue; $found = true; ?>
                <?php $template = 'wallpaper_preview' ?>
                    <li class="res_<?= $res->resolution_width . 'x' . $res->resolution_height ?>">
                    <a href="<?= $this->route_links->build_link($template, $search_replace + array('{R_WIDTH}' => $res->resolution_width, '{R_HEIGHT}' => $res->resolution_height)); ?>"><strong><?= $res->resolution_name; ?></strong></a>
                    </li>
                <?php } ?>
                </ul>
                <?php if (!$found) { ?>
                <div data-target=".res_g_<?= $i ?>" class="not_found_res">   </div>
                <?php } ?>
            </td>
        </tr>
        <?php $i++; ?>
        <?php } ?>
    </table>

那么,我如何在PHP中有一个条件来不输出没有可用分辨率的组呢?

EN

回答 1

Stack Overflow用户

发布于 2018-06-15 10:40:52

你可以IF条件就在代码之后<?php foreach ($group as $res) { ?>

比如:<?php foreach ($group as $res) { if(<YOUR_RESOLUTION_CONDITION>) {?>

别忘了关闭花括号

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100004935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档