PHP-需要按字母顺序垂直打印5列列表
作者:互联网
拥有一个主要由IE用户查看的网页,因此CSS3成为不可能.
我希望它列出如下:
A D G
B E H
C F I
当前列出的功能如下:
A B C
D E F
G H I
function listPhoneExtensions($group,$group_title) {
$adldap = new adLDAP();
$group_membership = $adldap->group_members(strtoupper($group),FALSE);
sort($group_membership);
print "
<a name=\"".strtolower($group_title)."\"></a>
<h2>".$group_title."</h2>
<ul class=\"phone-extensions\">";
foreach ($group_membership as $i => $username) {
$userinfo = $adldap->user_info($username, array("givenname","sn","telephonenumber"));
$displayname = "<span class=\"name\">".substr($userinfo[0]["sn"][0],0,9).", ".substr($userinfo[0]["givenname"][0],0,9)."</span><span class=\"ext\">".$userinfo[0]["telephonenumber"][0]."</span>";
if($userinfo[0]["sn"][0] != "" && $userinfo[0]["givenname"][0] != "" && $userinfo[0]["telephonenumber"][0] != "") {
print "<li>".$displayname."</li>";
}
}
print "</ul><p class=\"clear-both\"><a href=\"#top\" class=\"link-to-top\">↑ top</a></p>";
}
呈现HTML的示例:
<ul class="phone-extensions">
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
<li><span class="name">Barry Bonds</span><span class="ext">8281</span></li>
<li><span class="name">Gerald Clark</span><span class="ext">8211</span></li>
<li><span class="name">Juan Dixon</span><span class="ext">8282</span></li>
<li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li>
<li><span class="name">Freddie Flank</span><span class="ext">2281</span></li>
<li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li>
<li><span class="name">Kim Moore</span><span class="ext">5767</span></li>
</ul>
感谢您帮助它垂直列出alpha.
解决方法:
我会将关键数据加载到数组中,以便您可以对它们进行计数并以所需的顺序遍历它们.然后使用如下算法以正确的顺序获取它们:
$items = BuildItemArray(); // Get the values into an array.
$columnCount = 5;
$itemCount = count($items);
$rowCount = ceil($itemCount / $columnCount);
for ($i = 0; $i < $rowCount * $columnCount; $i++)
{
$index = ($i % $columnCount) * $rowCount + floor($i / $columnCount);
if ($index < $itemCount)
{
DisplayItem($items[$index]);
}
else
{
DisplayBlank();
}
}
我认为应该可以,但尚未测试.
标签:list,php,modulus 来源: https://codeday.me/bug/20191106/1999442.html