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