大佬教程收集整理的这篇文章主要介绍了从 foreach 循环 PHP 中删除特定的迭代,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下循环,如果 type == 'news' 且未读计数为 0,我想排除记录 我尝试过未设置选项,但对我不起作用。
$f = new stdClass();
$f->course_ID = $forum->course;
$f->type = $forum->type;
$f->unread = $unread;
$forum->type = $forum->type == 'news' ? 'Announcements' : 'forums';
//need fix here
if($forum->type =='news' && $unread ==0){
unset($f);}
$results[$forum->type][] = $f;
输出:
data: {
Announcements : [{}]
//fix should apply here. if type is news and unread =0 it shouldn show
newa: [{}]
}
您可以更改逻辑,只存储那些不是新闻或已阅读的内容
if($forum->type !='news' || $unread != 0){
$results[$forum->type][] = $f;
}
(尽管使用 unread
标志可能会有点混乱,可能值得更改逻辑以使用名为 read
的标志)
以上是大佬教程为你收集整理的从 foreach 循环 PHP 中删除特定的迭代全部内容,希望文章能够帮你解决从 foreach 循环 PHP 中删除特定的迭代所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。