[英]Echo divs inside Foreach loop
Im developing a web page which contains a posting section. 我正在开发一个包含发布部分的网页。 I have an
Array
called $posts
which contains Title
, body
, date
, and name
of the image from the post (rows come from a data base). 我有一个名为
$posts
的Array
,其中包含Title
, body
, date
和帖子中图像的name
(行来自数据库)。 This array is filled with all postings in the page, and when I use a foreach I want to echo these variables inside this block of code when running a foreache: 该数组充满了页面中的所有帖子,当我使用foreach时,我希望在运行前臂时在此代码块内回显这些变量:
<div class="col-lg-12 text-center">
<img class="img-responsive img-border img-full" src="../img/NAME.jpg" alt="">
<h2>TITLE
<br>
<small>DATE</small>
</h2>
<p>BODY</p>
<a href="#" class="btn btn-default btn-lg">Button</a>
<hr>
</div>
This is the structure of the array: 这是数组的结构:
$post= [
"title",
"date",
"body",
"name"
];
Just use below code in foreach condition 只需在foreach条件下使用以下代码
<?php foreach($post as $po){ ?>
<div class="col-lg-12 text-center">
<img class="img-responsive img-border img-full" src="<?php echo $po['name'];?>" alt="">
<h2><?php echo $po['title'];?>
<br>
<small><?php echo $po['date'];?></small>
</h2>
<p><?php echo $po['body'];?></p>
<a href="#" class="btn btn-default btn-lg">Button</a>
<hr>
</div>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.