我是初学者,正在尝试将静态数据模板转换为动态数据。现在我遇到了一个问题,我必须使用 for each 循环从数组中获取数据,然后在某些div 上显示。
有 3 个类似的div 容器,但第三个有一个额外的类可以将其移动到右侧..例如:(div1 => clas= "hello", div2 => class = "hello" , div3 => class = "hello floatrt" >)
.
问题是我的数据被显示,但由于类="floatrt"的荒谬。我的div 是垂直显示的。但是根据静态模板设计,它们在一行中..
如何将类添加到从数据库生成的第二个或第三个或其他div 中,而不是第一个div。
试试这个
$count = 1;
foreach ( $array as $k => $v ) {
// do anything here
if ($count % 3 ==0) {
echo '<div1 clas= "hello floatrt" ></div>';
} else {
echo '<div1 clas= "hello" ></div>';
}
$count++;
}