How to use the TP5.1 template Loop label (code)

Source: Internet
Author: User
This article brings the content is about the TP5.1 template cycle label use Method (code), there is a certain reference value, the need for friends can refer to, I hope to help you.

<?phpnamespace app\test\controller;use Think\controller;class Index extends controller{public    function Index (    {        $list = [            ' user1 ' =>[                ' name ' = ' Imooc ',                ' email ' = ' imooc@qq.com '            ],            ' User2 ' =>[                ' name ' = ' 104 ',                ' email ' = ' 104@qq.com '            ],            ' user3 ' =>[                ' name ' = ' CJK ',                ' email ' = ' cjk@qq.com '            ]        ;        $this->assign (' list ', $list);        return $this->fetch ();}    }

THINPHP5.1 provides three ways for us to use loops in view

{Volist} {/volist}

{foreach} {/foreach}

{for} {/for}

The variable name in the first volistname=assign id= the keyoffset= in the array begins the loop position length= step {volist name= ' list ' id= ' vo ' offset= ' 0 ' length= ' 3 '}<p >{$key}: {$vo. Name}: {$vo. email}</p>{/volist} The variable name in the second foreachname=assign item= array subscript {foreach in the keykey= array Name= ' list ' item= ' vo ' key= ' KKK '}<p>{$kkk}: {$vo. Name}</p>{/foreach} The third forstart= to start the loop position end= end the position of the loop step = Step name=for $i{for start= ' 1 ' end= ' step= ' k ' name= $k}<p>{!--default name}</p>{/for}< start= ' 1 ' end= '}<p>{$i}</p>{/for}

You can use {php}{/php} to insert PHP code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.