设为首页 加入收藏

TOP

laravel中利用循环实现隔行换色
2019-09-19 11:10:28 】 浏览:55
Tags:laravel 利用 循环 实现 隔行

1.首先在你的路由文件定义好访问的路径

2.

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>laravel中的for循环</title>
</head>
<body>
<h1>for循环</h1>

@for($i=0;$i<=10;$i++)
@if($i%2==0)
<h1 style="background-color: red">{{$i}}</h1>
@else
<h1 style="background-color: blue">{{$i}}</h1>
@endif
@endfor


</body>
</html>

2.也可以使用while循环进行操作
  {{$i=0}}
@while($i<10)
@if($i%2==0)
<h1 style="background-color: red">{{$i}}</h1>
    @else
<h1 style="background-color: blue">{{$i}}</h1>
@endif
{{$i++}}
@endwhile
缺点:使用while进行循环的时候{{$i=0}}{{$i++}}也会同时被输出到页面中

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇CentOS 7使用yum安装PHP5.6 下一篇laravel模板布局

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目