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). 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:
<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
<?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 } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.