Jump to content

re index an array after removing duplicates


mmgareth

Recommended Posts

If I have an array....

 

$test = array("apple","orange","apple","apple","cherry");

 

the indexes are

0 = apple

1 = orange

2 = apple

3 = apple

4 = cherry

 

When I remove duplicated using array_unique, I am left with this...

 

0 = apple

1 = orange

4 = cherry

 

But I really want to be left with this...

 

0 = apple

1 = orange

2 = cherry

 

I have tried $test = array_merge(array_flip(array_flip($test))), which seems to work, but gives Warning errors. 'array_flip() [function.array-flip]: Can only flip STRING and INTEGER values!'

 

Can anyone help?

 

Thanks

 

 

Gareth

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.