用php动态数据确定最后一行

I am generating a dynamic list with php which looks like picture. It has 4 columns(fixed); but rows can vary.

GREEN = first column
RED = last row

How can I get the GREEN and RED ones (for css purpose)?

echo '<ul>'
foreach($data as $v){
   echo '<li>$v</li>'
}
echo '</ul>'

enter image description here

Explained: each block is a li. the markup comes out like this:

<div class="content">
  <ul>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
    <li>some data</li>
  </ul>
</div>

and CSS

.content{ border-top:solid #000 1px, border-bottom:solid #000 1px}
ul{ border-left:solid #000 1px}
li{border-bottom:solid #000 1px; border-left:solid #000 1px}
  • The 1st column (1st, 5th and 9th li) will not have border-left.
  • The last row (8th and 9th li) will not have border-bottom

all i want is the whole thing looks like a table with cells. i cannot use table here, so i am trying to use list which looks like table. the lists are generating dynamically. so items can vary. I hope I am clear now.

How about this:

CSS

div.content {
    width: 403px;
    border: 1px solid black;
}

ul {
    overflow: hidden;
    list-style: none;
    width: 403px;
    margin: 0 0 -1px 0;
    padding: 0;
}

li {
    margin: 0;
    padding: 0;
    width: 100px;
    float: left;
    border-right: 1px solid black;
    border-bottom: 1px solid black; 
}

li:nth-child(4n+4) {
    border-right: 0;
}

Demo

Try before buy

You should probably use CSS to do this instead of PHP. Take a look at CSS nth-child pseudo-element.