PHP从数组中创建两个无序列表

PHP从数组中创建两个无序列表,php,html-lists,Php,Html Lists,我试图从一个PHP数组中创建两个无序列表,我发现这正是我要寻找的,但我希望第一个列表包含11项,第二个列表包含其余项。这是我的密码: <?php if ($rows) : $items = count($rows); $split = ceil($items/2); $firsthalf = array_slice($rows,$split); $secondhalf = array_slice($rows,0,$split); ?> &

我试图从一个PHP数组中创建两个无序列表,我发现这正是我要寻找的,但我希望第一个列表包含11项,第二个列表包含其余项。这是我的密码:

<?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; ?>


以下是如何将数组拆分为11个项目,然后再拆分为其余项目:


以下是如何将阵列拆分为11个项目,然后再拆分为其余项目:

如果查看文档,可以看到您将分割的大小指定为第三个参数,而第二个参数是偏移量:

<?php 
    if ($rows) : 
      $firsthalf = array_slice($rows, 0, 11); // returns 11 rows from the start
      $secondhalf = array_slice($rows, 11); // returns everything after the 11th row
?>

如果查看文档,可以看到您将分割的大小指定为第三个参数,而第二个参数是偏移量:

<?php 
    if ($rows) : 
      $firsthalf = array_slice($rows, 0, 11); // returns 11 rows from the start
      $secondhalf = array_slice($rows, 11); // returns everything after the 11th row
?>


问题是什么?在你做
array\u切片之前,先洗牌
数组。如何让第一个列表有11个项目?问题是什么?在你做
array\u切片之前洗牌
数组。如何让第一个列表有11个项目这么多(答案与下面相同)-但感谢随附的文档:)非常感谢(与下面的答案相同)-但感谢随附的文档:)
// $items = count($rows);
// $split = ceil($items/2);
$firsthalf = array_slice($rows, 0, 11);
$secondhalf = array_slice($rows, 11);