PHP / HTML - 重新组织数组

时间:2010-08-23 13:44:07

标签: php html arrays html-lists

我有一个ID值的数组,如[2,34,7,46,16,19 ...]

每个ID都指向我用html显示的更多数据:

<ul>
  <li>
    content from 2
    content from 34
    content from 7
  </li>

  <li>
    content from 46
    content from 16
    content from 19
  </li>
  ...

请注意,在这种情况下,每个列表项中有3个条目。 如何以一种总共正好有5个列表项的方式将数组中的条目共享到每个<li>

例如,如果数组有15个项目,每个<li>有3个项目,或者如果数组有9个项目,则每个<li>至少有1个条目(其中4个将有2个)< / p>

1 个答案:

答案 0 :(得分:0)

array_chunk($myArray, count($myArray) / 5)应该有效。您可能需要稍微调整一下,例如计数/ 5上的ceilfloor,但这是正确的方向。

http://php.net/manual/en/function.array-chunk.php