I am attempting to make an html element that contains x
amount of other div
s created by a function where x
is dependent on the number of elements $allposts
contains.
<div id="postings">
<?php
foreach($allposts as $key => $value){
createPost($key, $value);
}
?>
</div>
This html and php code above is my attempt to create a "posting" for each item that is found in the $allposts
array.
<?php
function createPost($author, $input)
{
$data = [];
$i = 0;
foreach($input as $key => $value){
$data[$i] = $value;
$i++;
}
echo "<div>
<span class='post-title'>$data[0]</span>
<span class='post-author'>$author</span>
<span class='post-date'>$data[1]</span>
<p class='post-desc'>$data[2]</span>
</div>";
}
?>
This is the php document that contains the function createPost($author, $input)
.
The function works but it seems that each time the function is being called, the previous post is overridden leaving only one post visible which ends up being the last one in the array.