如何在laravel刀片视图中打破foreach循环? [英] How to break a foreach loop in laravel blade view?

查看:129
本文介绍了如何在laravel刀片视图中打破foreach循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个循环:

@foreach($data as $d)
    @if(condition==true)
        {{$d}}
        // Here I want to break the loop in above condition true.
    @endif
@endforeach

如果满足条件,我想在数据显示后中断循环.

I want to break the loop after data display if condition is satisfied.

如何在laravel刀片视图中实现?

How it can be achieved in laravel blade view ?

推荐答案

来自刀片文档:

使用循环时,您也可以结束循环或跳过当前循环 迭代:

When using loops you may also end the loop or skip the current iteration:

@foreach ($users as $user)
    @if ($user->type == 1)
        @continue
    @endif

    <li>{{ $user->name }}</li>

    @if ($user->number == 5)
        @break
    @endif
@endforeach

这篇关于如何在laravel刀片视图中打破foreach循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆