[SOLVED] Unset array and then shift next one to fill in...?

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
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

[SOLVED] Unset array and then shift next one to fill in...?

Post by tomfra »

When I unset array it indeed removes the element I wanted to get rid of but instead of shifting the array it simply skips it so it looks like:

Array
(
[1] => string2
[3] => string3
)

In other words, [0] & [2] have been skipped in this example. How can I make it so that the resulting array looks like:

Array
(
[0] => string2
[1] => string3
)

Thanks!

Tomas
Last edited by tomfra on Thu Aug 19, 2004 7:10 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I do not know if there is an easier way but you could use $array=array_values($array);
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

It seems to be working :)

Thanks a lot! I knew it would be something as simple as this but just couldn't find it.

Tomas
Post Reply