这是一个循环,我想将其限制为2个输出,并为进一步的输出创建另一个循环。。我是的初学者
在此处输入代码
<?php if ($informations) { ?>
<div class="column">
<h3>
<?php echo $text_information; ?>
</h3>
<ul>
<?php foreach ($informations as $information){ ?>
<li><a href="<?php echo $information['href']; ?>">
<?php echo $information['title']; ?>
</a></li>
<?php } ?>
</ul>
</div>
<?php } ?>
试试这个。
<?php if ($informations) { ?>
<div class="column">
<h3><?php echo $text_information; ?></h3>
<ul>
<?php
$i=1;
foreach ($informations as $information){
if($i==2)
{
break;
}
?>
<li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li>
<?php
$i++;
} ?>
</ul>
</div>
<?php } ?>
对于其他值。
<?php if ($informations) { ?>
<div class="column">
<h3><?php echo $text_information; ?></h3>
<ul>
<?php
$i=1;
foreach ($informations as $information){
if($i<2)
{
continue;
}
?>
<li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li>
<?php
$i++;
} ?>
</ul>
</div>
<?php } ?>
有点模糊,但我猜您正在寻找array_couck,
$new_array = array_chunk($informations, 2, true);