-2

Possible Duplicate:
How do you reindex an array in PHP?

I have an array:

$input =array{0 => 'a', 1 => 'b',2 => 'c'}

Then, If I destroyed a variable in the array. Like this:

unset($input[1]);

The array will be like this:

$input =array{ 
    0 => 'a',
    2 => 'c' 
}

I want to rearrange it to become like this:

$input =array{ 
    0 => 'a',
    1 => 'c' 
}

How can I do it?

Thanks

Community
  • 1
  • 1
Hani
  • 41
  • 2
  • 4
  • editing soon-to-be-closed question is a brilliant idea – Your Common Sense Sep 03 '11 at 06:11
  • @Col. Shrapnel I voted to close as well. I hoped that editing would draw attention so that the fifth person can come by and close-vote it :) Actually, is there a way to see those questions which have 3 or 4 close-votes? – Foo Bah Sep 03 '11 at 06:15

3 Answers3

3

A quick look into the online manual suggests to use array_values();

$input = array_values($input);

Check the online manual for further information

Christian Bock
  • 441
  • 3
  • 6
1
$input = array_values($input);
aiham
  • 3,456
  • 27
  • 32
1

There are lots of sorting methods in php. Have a look: http://php.net/manual/de/array.sorting.php

As i think you want to sorty by key, ksort() should to it.

EDIT: Just have seen that ksort() is not what you are looking for. Use array_values()

Anna Völkl
  • 1,684
  • 2
  • 15
  • 27