• 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}
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • vtxyzzy

    (@vtxyzzy)

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get the last post in my for each’ is closed to new replies.