Reputation: 123
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"
];
Upvotes: 0
Views: 1441
Reputation: 1096
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 } ?>
Upvotes: 1