How to segment the foreach loop of an html page?

Source: Internet
Author: User
Tags smarty template
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 ";If ($ timer % $ has_n_cols = 0 or $ timer = $ count){Echo "\ n ";}$ Timer ++;} ?>
$ Value


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.

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10


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 ";If ($ timer % $ has_n_cols = 0 or $ timer = $ count){Echo "\ n ";}$ Timer ++;} ?>
$ Value
Thank you for your answer. I have finished it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.