[英]List with alphabetical headings
How can i extend the list with alphabetical headings. 我如何用字母标题扩展列表。 For Example: 例如:
A Anchor Animal 一个锚动物
B Bus Burn B巴士烧伤
E Eat Euro E吃欧元
This is my actually Code: 这是我的实际代码:
<ol class="items brand-items">
<?php foreach ($block->getBrands() as $brand): ?>
<li class="item brand-item">
<?php echo $block->escapeHtml($brand->getName()) ?>
</li>
<?php endforeach; ?>
</ol>
assuming your inputs as : 假设您的输入为:
$list = ['apple', 'and', 'another', 'ball', 'bat', 'cat', 'call'];
and your desired output be: 和您期望的输出是:
Array (
[a] => Array
(
[0] => apple
[1] => and
[2] => another
)
[b] => Array
(
[0] => ball
[1] => bat
)
[c] => Array
(
[0] => cat
[1] => call
)
)
you ought to do something like: 您应该做类似的事情:
$out = [];
foreach ($list as $brand) {
$out[substr($brand,0,1)][] = $brand;
}
print_r($out); print_r($ out);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.