我正在尝试按字母顺序对菜单进行分组并将其拆分为列。所以我有一个关联数组,我的项目已经按字母排序。
foreach ($category['children'] as $children) {
$firstChar = $children['name'][0];
// if character is a number set it as #
if (is_numeric($firstChar)) {
$firstChar = "#";
}
if ($firstChar !== $previousChar) {
echo '<li class="submenu_tag">'.strtoupper($firstChar).'</li>';
$previousChar = $firstChar;
}
echo '<li><a href="'.$children['href'].'">'.$children['name'].'</a></li>';
$count++;
if ($count == 11) {
echo '</ul></div>';
echo '<div><ul>';
$count = 0;
}
}
echo '</ul></div>';
我现在拥有的内容将输出此内容。
<div> <div> <div>
A Cow Fawn
Apple Crab Fish
Ape Fox
Ant D
Dog G
B Gazette
Boy E Goose
Ball Elephant Gorilla
Bad Egg
Elk H
C Hedgehog
Camel F Hen
Cat Falcon
</div> </div> </div>
如果属于一个组的下列几个项目将超过11行(不包括中间的空白区域),那么它将会移动到一个新的div。像这样:
<div> <div> <div>
A C F
Apple Cat Falcon
Ape Cow Fawn
Ant Crab Fish
Fox
B D
Boy Dog G
Ball Gazette
Bad E Goose
Elephant Gorilla
Egg
Elk .....
</div> </div> </div>