0
我想按字母對菜單進行分組,並將它們按列分組。所以我有一個關聯數組,其中我的項目已經按字母排序。按列排序菜單項
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>
你可以給一個示例輸入! –
它只是'$ children ['id']''$ children ['name']'和'$ children ['href']' – John