您可以做
$n = 3;
echo "
for($i=0; $i
$temp = array();
$temp = $gallery[$i];
echo "
if($i % $n ==0 && $i!=0){
echo "
";}
}
echo '
';编辑:
如果你想这样做“正确”的方式 - 通过构建语法正确的HTML,你需要做的:
$n = 3;
echo "
$gallery_count = count($gallery);
for($i=0; $i
$temp = array();
$temp = $gallery[$i];
echo "
if($i != 0){
if($i % $n == 0 && $i != $gallery_count-1){
echo "
";}
else{
echo ""; //if it is the last in the loop - do not echo
}
}
}
//example - if the last 2 `td`s are missing:
$padding_tds = $gallery_count % $n;
if($padding_tds != 0){
$k = 0;
while($k < $padding_tds){
echo "
";}
}
echo '
';