reset array keys, starting at 0

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
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

reset array keys, starting at 0

Post by GeXus »

I have an array, and based on a condition it will unset the first element... The array always starts out with keys 0,1,2,3, etc.. So when I unset the first one i'm left with 1,2,3, etc.. How do I resest the keys? so that they start at 0 again? Is there a function to simply do this?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

perfect.. thanks!
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Re: reset array keys, starting at 0

Post by stereofrog »

GeXus wrote:I have an array, and based on a condition it will unset the first element... The array always starts out with keys 0,1,2,3, etc.. So when I unset the first one i'm left with 1,2,3, etc.. How do I resest the keys? so that they start at 0 again? Is there a function to simply do this?
Do not unset() the first elem, do array_shift() instead.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ah, excellent.. double whammy.. thanks!
Post Reply