我目前有一个人员列表 (
),我已将其分为两列。但在完成代码后,我一直想知道是否有更有效或更干净的方法来完成同样的事情。
echo "<table class='area_list'><tr>";
// Loop users within areas, divided up in 2 columns
$count = count($areaArray);
for($i=0 ; $i<$count ; $i++) {
$uid = $areaArray[$i];
// get the modulus value + ceil for uneven numbers
$rowCalc = ($i+1) % ceil($count/2);
if ($rowCalc == 1) echo "<td><ul>";
// OUTPUT the actual list item
echo "<li>{$users[$uid]->profile_lastname}</li>";
if ($rowCalc == 0 && $i!=0) echo "</ul></td>";
}
echo "</tr></table>";
不知道这是否是@llia的意思,但是像这样的for循环怎么样:
//declare how many columns are needed
$cols=2;
//iterate over each row of entries (down the column)
for ($i=0;i<$count;i+=cols){
echo "<td><ul>";
//entry loop (across the row)
for($j=0;j<$cols;j++){
//whose line is it anyway?
$uid = $areaArray[$i+$j];
echo "<li>{$users[$uid]->profile_lastname}</li>";
}
//end entry loop
echo "</ul></td>";
}
//end row loop
这样,您可以设置任意数量的列。
如果我在等待水壶烧开以获得我急需的咖啡时错过了一些东西,请原谅我!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)