How to display two table columns per row in php loop

前端 未结 4 1228
無奈伤痛
無奈伤痛 2020-12-03 08:36

I would like to display data, two columns per row during my foreach. I would like my result to look like the following:

 
V
4条回答
  •  日久生厌
    2020-12-03 09:10

    You can use array_chunk() to split an array of data into smaller arrays, in this case of length 2, for each row.

    Note that if you have an odd number of values, this will leave a final row with only one cell. If you want to add an empty cell if necessary, you could check the length of $row within the outer foreach.

提交回复
热议问题