首先,我不知道如何在php中计数,也许有人可以推荐我一个很好的阅读来源;
其次,我并不是要为我解决这个问题,而只是想要一个有意义的提示或更简单的解释;
这是我的功能:
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<a href="<?php echo $category['href']; ?>"><p><?php echo $category['name']; ?></p></a>
<?php if ($category['children']) { ?>
<div>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<ul>
<li class="none"><h1><?php echo $category['children'][$i]['name']; ?></h1></li>
<?php if ($category['children'][$i]['children_level2']) { ?>
<?php for ($wi = 0; $wi < count($category['children'][$i]['children_level2']); $wi++) { ?>
<li>
<a href="<?php echo $category['children'][$i]['children_level2'][$wi]['href']; ?>"><?php echo $category['children'][$i]['children_level2'][$wi]['name']; ?></a>
</li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
我想要这部分,每 13 li 元素创建一个新的 .ul。./ul. 标签
<?php if (isset($category['children'][$i])) { ?>
<ul>
<li class="none"><h1><?php echo $category['children'][$i]['name']; ?></h1></li>
<?php if ($category['children'][$i]['children_level2']) { ?>
<?php for ($wi = 0; $wi < count($category['children'][$i]['children_level2']); $wi++) { ?>
<li>
<a href="<?php echo $category['children'][$i]['children_level2'][$wi]['href']; ?>"><?php echo $category['children'][$i]['children_level2'][$wi]['name']; ?></a>
</li>
<?php } ?>
<?php } ?>
</ul>
<ul><li>maximum of 13 elements</li></ul>
after 13 <li></li> elements create new <ul></ul> tags and put the 14 <li></li> element into the new <ul></ul> tag
我希望我解释了我想做什么,现在我会等待你的答案,
ps 这更多是为了我的学习技能而不是实际工作,所以谢谢你的建议