我想從一個PHP數組創建兩個無序列表,我發現this thread這幾乎是我在找的東西,但是我希望第一個列表有11個項目,剩下的第二個清單。這裏是我的代碼:PHP從數組中創建兩個無序列表
<?php if ($rows) :
$items = count($rows);
$split = ceil($items/2);
$firsthalf = array_slice($rows,$split);
$secondhalf = array_slice($rows,0,$split);
?>
<div class="tickets">
<div class="col1">
<ul>
<?php foreach ($firsthalf as $item) : ?>
<li><a href="">test 1</a></li>
<?php endforeach; ?>
</ul>
</div>
<div class="col2">
<ul>
<?php foreach ($secondhalf as $item) : ?>
<li><a href="">test 2</a></li>
<?php endforeach; ?>
</ul>
</div>
<div class="clear"></div>
</div>
<?php endif; ?>
和問題是什麼? –
在你做'array_slice'之前,只需'shuffle'數組。 – sberry
如何使第一個列表有11個項目 – SoulieBaby