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
A quick look into the online manual suggests to use array_values();
$input = array_values($input);
$input = array_values($input);
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()