Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 775 Bytes

10.循环遍历.md

File metadata and controls

55 lines (43 loc) · 775 Bytes

循环遍历

  • for
  • foreach
  • while
  • dowhile

编译方法

$tags_loop=array(
	"{for([:any])}"				=>"<?php for($1){ ?>",
	"{/for}"					=>"<?php } ?>",
	"{foreach([:any])}"			=>"<?php foreach($1){ ?>",
	"{/foreach}"				=>"<?php } ?>",
	"{while([:any])}"			=>"<?php while($1){ ?>",
	"{/while}"					=>"<?php } ?>",
	"{do}"						=>"<?php do{ ?>",
	"{dowhile([:any])}"			=>"<?php }while($1); ?>",   //while和以上的while冲突,需要使用dowhile
);

案例

for标签

{for($i=0;$i<4;$i++)}
 {$i}
{for($j=0;$j<4;$j++)}
 {$j}
{/for}
{/for}

foreach标签

{foreach($list as $k=>$v)}
	<tr>
		<td>{$k}</td>
		<td>{$v}</td>
	</tr>
   {foreach($list as $k2=>$v2)}
	<tr>
		<td>{$k2}</td>
		<td>{$v2}</td>
	</tr>
	{/foreach}
{/foreach}