THINKPHP5.1模板循环标签

<?php
namespace app\test\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        $list = [
            'user1'=>[
                'name' =>'imooc',
                'email'=>'[email protected]'
            ],
            'user2'=>[
                'name' =>'104',
                'email'=>'[email protected]'
            ],
            'user3'=>[
                'name'=>'cjk',
                'email'=>'[email protected]'
            ]

        ];

        $this->assign('list',$list);
        return $this->fetch();
    }
}

THINPHP5.1提供了三种方式供我们在view中使用循环

{volist}{/volist}

{foreach}{/foreach}

{for}{/for}

第一种volist
name=assign中的变量名
id=数组中的key
offset=开始循环的位置
length=步长

	{volist name='list' id='vo' offset='0' length='3'}
		<p>{$key} : {$vo.name} : {$vo.email}</p>
	{/volist}


第二种foreach
name=assign中的变量名
item=数组中的key
key=数组中的下标
	{foreach name='list' item='vo' key='kkk'}
		<p>{$kkk} : {$vo.name}</p>
	{/foreach}



第三种for
start=开始循环的位置
end=结束循环的位置
step=步长
name=for循环中的$i
	{for start='1' end='10' step='2' name='k'}
		<p>{$k}</p>
	{/for}

	
	<!-- 默认name -->
	{for start='1' end='10'}
		<p>{$i}</p>
	{/for}

可以使用{php}{/php}插入php代码

猜你喜欢

转载自blog.csdn.net/weixin_38468437/article/details/81606888