PHP的重新排序数组 [英] php Reorder an array

查看:146
本文介绍了PHP的重新排序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组中像PHP:

i have an array in php like:

$a = array(0=>'a', 1=>'b', 2=>'c', 3=>'d');

现在我取消设置元素的数组:

Now i unset an element in array:

unset($a[2]);

现在我有数组:

$a = array(0=>'a', 1=>'b', 3=>'d');

但我想重新排序的数组中,索引组织的数字,如:

But i want to reorder the array such that the indexes are numerically organized, like:

$a = array(0=>'a', 1=>'b', 2=>'d');

我能做些什么让这种变化?

What i can do to get this change?

推荐答案

这应该这样做:

$new_array = array_values($old_array);

这篇关于PHP的重新排序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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