如何重新键与非连续的数字键排列 [英] How to re-key array with non-sequential numeric keys

查看:143
本文介绍了如何重新键与非连续的数字键排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组:

 阵列

 [0] => ololo
 [2] =>测试
 [3] =>哈哈
 [7] =>不错

我怎样才能改变数组的索引,以这样的:

 阵列

 [0] => ololo
 [1] =>测试
 [2] =>哈哈
 [3] =>不错


解决方案

从PHP.net:


  

array_values​​()返回输入数组中的所有值和索引数值数组。


来源

  $ ARR = array_values​​($ ARR);

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 numerically the array.

Source

$arr = array_values($arr);

这篇关于如何重新键与非连续的数字键排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆