【发布时间】:2020-09-02 20:44:37
【问题描述】:
我有一个如下所示的 php 代码,其中通过 B 行,我计算了按字母顺序对数组结果进行分组时使用的标题字符。 A 行打印 4.DEMO
php代码:
<?php
$beta_lists = array (
'Àpple' => 'http://www.abc.mno/apple/',
'Ball' => 'http://www.abc.mno/ball/',
'Builders' => 'http://www.abc.mno/builders/',
'Bowling' => 'http://www.abc.mno/bowling/',
'Correct' => 'http://www.abc.mno/correct/',
'Campaign' => 'http://www.abc.mno/compain/',
'Direct' => 'http://www.abc.mno/direct/',
'Degree' => 'http://www.abc.mno/degree/'
);
ksort($beta_lists);
$groups = array();
foreach ($beta_lists as $title => $value) {
$groups[remove_accents(mb_substr($title, 0, 1))][$title] = $value;
}
ksort($groups);
print_r($groups);
echo count($groups); // Line A
if(count($groups)%2==0) {
} else {
}
问题陈述:
我想知道我应该在上面的 php 代码中进行哪些更改,以便它在标题字符下按列打印列表项 (如下所示的 2 列)。
第二列应始终以标题字符开头,而不是列表项。对于偶数个标题字符,50% 的标题字符及其列表项应位于左侧 并且 50% 的标题字符及其列表项应位于右侧。
如果我们有奇数个标题字符(比如说 7 个),那么 4 个标题字符应该在第 1 列,3 个标题字符应该在第 2 列 第二列中没有任何列表被孤立。
A C
Apple Correct
B Compaingn
Ball D
Builders Direct
Bowling Degree
这是我尝试过的:
以下 html 代码需要与上面的 php 代码集成,以便列表按列显示在 标题字符下。
html代码:
<ul class="shows-list">
<li class="shows-list__letter">
<h1 class="shows-list__letter-title"><?php echo esc_html( $title_character ) ?></h1> <!-- For title character -->
<a class="shows-list__link" href="<?php echo esc_url( $permalink ); ?>"><h2 class="shows-list__title"><?php echo esc_html( $title ); ?></h2></a>
</li>
</ul>
这里的 $title 是 Apple、Ball、Builders、Bowling、Correct、Compaign、Direct 和 Degree。
【问题讨论】:
-
演示链接似乎已损坏。
-
是的,小提琴有一些问题。它很快就会起来。
-
你为什么不用css来做这个?
标签: php html html-lists