32

I have an array:

Array
(
 [0] => ololo
 [2] => test
 [3] => haha
 [7] => nice
)

How can I change the indexes of the array to this:

Array
(
 [0] => ololo
 [1] => test
 [2] => haha
 [3] => nice
)
0

5 Answers 5

73

From PHP.net:

array_values() returns all the values from the input array and indexes the array numerically.

Source

$arr = array_values($arr);
Sign up to request clarification or add additional context in comments.

Comments

7

array_values() is probably what you want. See: http://php.net/function.array-values

$myArray = array_values($myArray);

Comments

3

This will re-index the array keys:

array_values($array)

Comments

2

array_values()

Comments

2

If you have your initial array within $a variable, you can just do the following:

$a = array_values($a);

Which will basically return values from within your original array, and will do it in the another array.

Is it clear enough?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.