Determine when pointer has reached end of array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fgomez
Forum Commoner
Posts: 61
Joined: Mon Sep 26, 2005 11:23 pm
Location: Washington, DC

Determine when pointer has reached end of array?

Post by fgomez »

Hello,

I am using foreach to move through an array. I want to treat the last item differently than all the preceding ones. How do I determine when I've reached the the last spot?

Thanks!
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

count the array elements, then decrement as you loop through it.
fgomez
Forum Commoner
Posts: 61
Joined: Mon Sep 26, 2005 11:23 pm
Location: Washington, DC

Determine when pointer has reached end of array?

Post by fgomez »

Thank you. This did exactly what I needed it to.
Post Reply