PHP foreach 帮助
我正在为我的网站构建一个扩展,允许用户收藏帖子,但是我遇到了一个问题,
我在我的视图中运行此代码,
<?php if(isset($favourites)) : ?>
<?php foreach ($favourites as $fav) : ?>
<a href="/favourites/save_feed/<?php echo $f['feed_id']; ?>" class="<?php echo ($f['feed_id'] == $fav['feed']) ? 'faved' : 'fave'; ?>">Fave</a>
<?php endforeach;?>
<?php else : ?>
<a href="/favourites/save_feed/<?php echo $j['feed_id']; ?>" class="fave">Fave</a>
<?php endif; ?>
但是我的问题是,如果有两个帖子标记为收藏夹,它将循环遍历两个帖子条目并在一篇文章上显示两次最喜欢的链接,我怎样才能使其循环浏览帖子并添加最喜欢的链接(如果该文章确实是最喜欢的)?
I am building an extention to my site that allows users to favourite posts, I am however having a a problem,
I am running this code in my view,
<?php if(isset($favourites)) : ?>
<?php foreach ($favourites as $fav) : ?>
<a href="/favourites/save_feed/<?php echo $f['feed_id']; ?>" class="<?php echo ($f['feed_id'] == $fav['feed']) ? 'faved' : 'fave'; ?>">Fave</a>
<?php endforeach;?>
<?php else : ?>
<a href="/favourites/save_feed/<?php echo $j['feed_id']; ?>" class="fave">Fave</a>
<?php endif; ?>
However my problem is that if there are two posts marked as a favourite it will loop over both entries and show the favourite link twice on one post, how can I make it so it loops through the posts and adds a favourite link if that post is indeed a favourite?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解你的问题:
如果你已经有了链接列表,看起来就像你用
$j
所做的那样:完成。
If I understand your question:
If you have the list of links already, which it looks like you do with
$j
:done.