繁体   English   中英

如何跳过关联数组中while循环的迭代意味着我们要像这样执行first,second,fourth,fifth?

[英]how to skip iteration of while loop in associative array means we want to execute first ,second, fourth,fifth like this?

我正在创建一个CMS系统。 如果帖子未发布,则它将不会以html呈现,否则将以html显示。 因此,如果我从数据库“ cms”中获取关联数组,则该数组具有一些已发布和未发布的帖子。 因此,如何跳过未发布的帖子,仅显示html中的已发布帖子。

我已经尝试过条件

            <!-- First Blog Post -->
            <h2 style = "color:green;">
                   <?php echo $post_title ;?></a>
            </h2>
            <p class="lead">
                 by <?php echo $post_author ;?></a>
            </p>
            <p><span class="glyphicon glyphicon-time"></span><?php $post_date ?></p>
            <hr>
            <img class="img-responsive" src="images/<?php echo $post_image ;?>" alt="">
            <hr>
            <p><?php echo $post_content ?></p>
            <a class="btn btn-primary" href="#">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>

            <hr>


             **<?php } ?> **    
     **<?php } **// <!--loop ends here so that we can fetch 'n' no. of posts and displaying each post like below HTML -->

                ?>
        </div>

如果发布==发布,则仅以html显示,否则不显示。

检查循环开始时是否未发布帖子。 然后使用继续跳过循环的其余部分。

while(items) { if(!$post->published) continue; // this part only runs if post is published }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM