His there any way I could know when I reach the last element into my foreach?
foreach($posts as $post)
{
// Show some posts
// If it is the last post in the foreach
if(LAST) {Show something special}
}
His there any way I could know when I reach the last element into my foreach?
foreach($posts as $post)
{
// Show some posts
// If it is the last post in the foreach
if(LAST) {Show something special}
}
Try something like this:
$last = count($posts);
foreach($posts as $post)
{
// Show some posts
// If it is the last post in the foreach
if(++$post_count == $last) {Show something special}
}Thank you. It worked well for me.
You must log in to post.