打开和关闭 HTML 个标签,中间有多个逻辑循环
Opening & Closing HTML tags with multiple logic Loops inbetween
我基本上是在尝试循环并正确显示我的类别
1) 如果深度为 1(类别)
,我需要调用 Div
、H3
和 UL
2) 如果深度等于 2(子类别)我将其推入 <li>
3) 问题是,如果我检测到深度 1 并显示第一个 Div
,我不知道如何在深度 2 语句之后调用 </div>
结束标记来关闭完成了。
<div class="col-md-4 header-navigation-col">
<h4>Category's Name</h4>
<ul>
<li><a>Sub Category</a></li>
<li><a>Sub Category</a></li>
</ul>
</div>
我的代码
@foreach($catWomen->getDescendants() as $descendant)
<?php if($descendant->depth == 1){
echo '<div class="col-md-4 header-navigation-col">';
echo '<h4>Category Name</h4>';
}elseif($descendant->depth == 2){
echo '<li><a>Sub Category</a></li>';
}
?>
@endforeach
如何关闭我的第一个 Div
?
$close_div = "";
@foreach($catWomen->getDescendants() as $descendant)
<?php
if($descendant->depth == 1){
echo($close_div);// first time it is empty string, then always is "</div>"
$close_div = "</div>";
echo '<div class="col-md-4 header-navigation-col">';
echo '<h4>Category Name</h4>';
}elseif($descendant->depth == 2){
echo '<li><a>Sub Category</a></li>';
}
?>
@endforeach
我基本上是在尝试循环并正确显示我的类别
1) 如果深度为 1(类别)
,我需要调用Div
、H3
和 UL
2) 如果深度等于 2(子类别)我将其推入 <li>
3) 问题是,如果我检测到深度 1 并显示第一个 Div
,我不知道如何在深度 2 语句之后调用 </div>
结束标记来关闭完成了。
<div class="col-md-4 header-navigation-col">
<h4>Category's Name</h4>
<ul>
<li><a>Sub Category</a></li>
<li><a>Sub Category</a></li>
</ul>
</div>
我的代码
@foreach($catWomen->getDescendants() as $descendant)
<?php if($descendant->depth == 1){
echo '<div class="col-md-4 header-navigation-col">';
echo '<h4>Category Name</h4>';
}elseif($descendant->depth == 2){
echo '<li><a>Sub Category</a></li>';
}
?>
@endforeach
如何关闭我的第一个 Div
?
$close_div = "";
@foreach($catWomen->getDescendants() as $descendant)
<?php
if($descendant->depth == 1){
echo($close_div);// first time it is empty string, then always is "</div>"
$close_div = "</div>";
echo '<div class="col-md-4 header-navigation-col">';
echo '<h4>Category Name</h4>';
}elseif($descendant->depth == 2){
echo '<li><a>Sub Category</a></li>';
}
?>
@endforeach