【发布时间】:2014-12-05 04:02:45
【问题描述】:
我正在尝试回到 foreach 语句,如下面的示例代码所示。 有没有办法做到这一点?
<?php
foreach($boxes as $box)
{
foreach($box as $thing)
{
?>
<img src="<?php echo $thing ?>"/>
<?php
}
}
?>
<!-- more html code here outside of foreach statement that don't want to be loop -->
// want to go back in to the foreach statement
<?php echo $thing; ?>
所以输出将是
<img src="1">
<img src="2">
<img src="3">
<div>this only appear once</div>
<img src="1"><p>1</p>
<img src="2"><p>2</p>
<img src="3"><p>3</p>
【问题讨论】:
-
我想以同样的顺序再次打印出同样的东西。不太确定插值是什么意思。
-
你不会再次运行循环吗? (在下一部分中还有另一个
foreach循环吗?) -
将 foreach 结果保存到变量中,然后在您想要的位置打印变量?