How to segment the foreach loop of an html page? How to segment the foreach loop of an html page ?, For example, if the first column reads five paragraphs for another paragraph and reads five of them, please answer! Thank you.
[CSDN] Daxia ~~~
High-end atmosphere,
Low-key luxury has connotation.
The weather is full of depth,
Cool? Bombing days...
Reply to discussion (solution)
You can directly perform foreach counting or use array_chunk to segment data.
Define a variable $ p = 0; $ p ++ after each loop;
If ($ p % 4 = 0) segments.
You can directly perform foreach counting or use array_chunk to segment data.
I want to intercept the page because the results are not satisfactory and the pages are not convenient,
Request: array_chunk instance
Http://www.w3school.com.cn/php/func_array_chunk.asp
It is not necessary to split the array or count
You only need to set the width and floating of each entry to arrange the entries in the containers
However, the order is from left to right, from top to bottom.
Instead of from top to bottom, from left to right
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
This is a reality in Google's browser. You can set the ul and li widths to implement any column.
Note the compatibility of browsers when writing styles. for example, if ie forgets the version, it does not support inline-block. you need to write hack.
It is better not to use lists for multiple rows and multiple columns. it is easier to use tables.
Test. php
$ Arr = array );$ Has_n_cols = 3; // actual columns$ Count = count ($ arr );$ Timer = 1;Foreach ($ arr as $ value){If ($ timer % $ has_n_cols = 1){Echo "\ n
";} Echo "\ n
$ Value | ";If ($ timer % $ has_n_cols = 0 or $ timer = $ count){Echo "\ n
";}$ Timer ++;} ?>
I don't know if the landlord is using the smarty template technology. if you are using it, give the foreach a name.
<{Foreach form = $ arr name = name1...}>
<{If $ smarty. foreach. name1.iteration % 5 = 0}>...
<{/Foreach}>
I think floating is the best way.
Introduce the css layout, and directly output it to the end...
You can use an if clause to determine the line break. if the line breaks, the tr label is used directly.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
This is a reality in Google's browser. You can set the ul and li widths to implement any column.
Note the compatibility of browsers when writing styles. for example, if ie forgets the version, it does not support inline-block. you need to write hack.
It is better not to use lists for multiple rows and multiple columns. it is easier to use tables.
Test. php
$ Arr = array );$ Has_n_cols = 3; // actual columns$ Count = count ($ arr );$ Timer = 1;Foreach ($ arr as $ value){If ($ timer % $ has_n_cols = 1){Echo "\ n
";} Echo "\ n
$ Value | ";If ($ timer % $ has_n_cols = 0 or $ timer = $ count){Echo "\ n
";}$ Timer ++;} ?>
Thank you for your answer. I have finished it.