php - 如何删除最后一个
在 Codeigniter 的 foreach 循环中标记?
问题描述
很抱歉发布这样的帖子,但我正在学习我希望所有结果都有一个 hr 或任何基于 html 的行,除了最后一个我放了一个换行符,但它看起来对我有帮助
foreach ($newsqry->result() as $n) {
$nr=$n->numrows();
$nlink = array_keys($routesAll, "news/index/" . $n->n_id);
?>
<div class="row">
<div class="col-md-6 imgpost">
<a class="post-imgn" href="<?=site_url($nlink)?>">
<img class=""src="<?=base_url("assets/uploads/news/thmb/$n->img")?>"alt="<?=character_limiter($n->title,'50')?>">
</a>
</div>
<div class="col-md-6 descpost">
<div class="post-category com" >
<?php
$t = $n->tags;
$s = explode(',', $t);
foreach ($s as $a) {
?>
<a class="tags" href="<?=site_url("news/view?tag=".strtolower(str_replace(' ','-',$a)))?>"><?=ucwords($a)?></a>
<?php } ?>
</div>
<h3 class="post-title news">
<a href="<?=site_url($nlink)?>"><?=character_limiter($n->title,'100')?>"</a>
</h3>
<ul class="post-meta">
<li><a href="<?=site_url("news/view?author=".strtolower(str_replace(' ','-',$n->author)))?>"><?=$n->author?></a></li>
<li><i class="fa fa-clock-o" aria-hidden="true"></i> <?=date("h:i A",strtotime($n->time))?> <?=date("F-d-y",strtotime($n->date))?></li>
</ul>
<p class="descfornews"><?=character_limiter(strip_tags($n->desc),'190')?></p>
</div>
</div>
<?php if($nr<1){echo "<hr>";}else{ echo "<h3>End of Page</h3>";}?>
<?php
}
?>
解决方案
I think you can do something like this. it will print
before the data printed, but there is $data variable to prevent it to print before the first data.
<?php
$data = 0;
$t = $n->tags;
$s = explode(',', $t);
foreach ($s as $a) {
if($data!=0){echo "<hr>";}
?>
<a class="tags" href="<?=site_url("news/view?tag=".strtolower(str_replace(' ','-',$a)))?>"><?=ucwords($a)?></a>
</div>
<h3 class="post-title news"><a href="<?=site_url($nlink)?>"><?=character_limiter($n->title,'100')?>"</a></h3>
<ul class="post-meta">
<li>
<a
href="<?=site_url("news/view?author=".strtolower(str_replace(' ','-',$n->author)))?>"><?=$n->author?></a>
</li>
<li>
<i class="fa fa-clock-o" aria-hidden="true"></i>
<?=date("h:i A",strtotime($n->time))?>
<?=date("F-d-y",strtotime($n->date))?></li>
</ul>
<p class="descfornews"><?=character_limiter(strip_tags($n->desc),'190')?></p>
</div>
</div>
<?php
}
echo("<h3>End of Page</h3>");
?>
推荐阅读
- reactjs - 单击卡片时如何路由到具有特定卡片详细信息的页面?
- javascript - 根据范围返回数组中的对象
- c++ - 为什么必须在线程销毁之前调用 join() 或 detach() ?
- c# - 未找到命令 dotnet ef
- arrays - 在二进制数组中查找集群组
- python - 尝试使用烧瓶和 apache 运行网站时出现 404 not found 错误
- r - 从数据框中创建一个列表:A 列是变量,B 列与 C 列中的值相关联
- c++ - 是否强制转换为仅包含 char[] 并从该数组中读取的结构定义良好?
- reactjs - 如何强制地将 prop 分配给 React 组件?
- c# - 如何将特定图像设置为 Fluent Design AcrylicBackgroundSource