Home  >  Article  >  Backend Development  >  php 把数组分为5个一组的

php 把数组分为5个一组的

WBOY
WBOYOriginal
2016-06-13 12:26:381623browse

php 把数组分成5个一组的
假设$list 是一组数组。里面包含多条数据信息。

我想把$list 分成5个一组 然后输出。

在模板输出循环每组::

<br />{loop $XXXX $x}<br />这是第X组:<br />1里面有$A $B $C<br />2里面有$A $B $C<br />3里面有$A $B $C<br />4里面有$A $B $C<br />5里面有$A $B $C<br />{/loop}<br />


估计得2个循环  第一个是总共的条数 第二个是每个里面的5个
------解决思路----------------------
<br /><?php<br />foreach(array_chunk(array(1,2,3,4,5,6,7,8,9,0,1), 5) as $val)<br />{<br />	foreach($val as $v)<br />	{<br />		echo $v,"\t";<br />	}<br />	echo "\n";<br />}<br /><br />


output:
<br />1	2	3	4	5	<br />6	7	8	9	0	<br />1	<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn