我有$array=array("nothing","1","2","3","4","5","6","7","8","9","10");
一段代码作为模板:
$var=<<<EOF
$array[0]
<div>
<!-- something else -->
<ul>
<li>$array[1]</li>
<li>$array[2]</li>
<li>$array[3]</li>
</ul>
<!-- something else -->
</div>
EOF;
我想在有数组元素时动态重复和修改这个 HTML 代码。我的意思是这个结果:
$var=<<<EOF
$array[0]
<div>
<!-- something else -->
<ul>
<li>$array[1]</li>
<li>$array[2]</li>
<li>$array[3]</li>
</ul>
<!-- something else -->
</div>
<div>
<!-- something else -->
<ul>
<li>$array[4]</li>
<li>$array[5]</li>
<li>$array[6]</li>
</ul>
<!-- something else -->
</div>
<div>
<!-- something else -->
<ul>
<li>$array[7]</li>
<li>$array[8]</li>
<li>$array[9]</li>
</ul>
<!-- something else -->
</div>
<div>
<!-- something else -->
<ul>
<li>$array[10]</li>
</ul>
<!-- something else -->
</div>
EOF;