开发者

How to re-key array with non-sequential numeric keys

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
)


From PHP.net:

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

Source

$arr = array_values($arr);


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

$myArray = array_values($myArray);


This will re-index the array keys:

array_values($array)


array_values()


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜