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

php 把数组分为5个一组的

WBOY
Release: 2016-06-13 12:26:38
Original
1647 people have browsed it

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 />
Copy after login


估计得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 />
Copy after login


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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template