PHP对齐阵列键值 [英] PHP Aligning Array Key Values

查看:87
本文介绍了PHP对齐阵列键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE了两天,并试图寻找在PHP手册,我仍然不记得函数对齐键值PHP数组。

I've Googled it for two days, and tried looking at the PHP manual, and I still can't remember that function that aligns the key values for PHP arrays.

所有我要找的是借此功能:

All I'm looking for is the function that takes this:

Array
(
    [0] => 1
    [3] => 2
    [4] => 3
    [7] => 4
    [9] => 5
)

和把它转换成这样的:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

基本上,数组首先被密钥排序(附连到他们自己的值留在它们),那么所有的按键都设置为所有的计数数字,连续,不跳过任何数目(0,1,2,3, 4,5,6,7,8,9 ......)。只见它正与ksort使用()几个月前,并不能看到记住或找到这个难以捉摸的功能。

Basically, the array is first sorted by key (their values attached to them stay with them), then all the keys are set to all the counting numbers, consecutively, without skipping any number (0,1,2,3,4,5,6,7,8,9...). I saw it being used with ksort() a few months ago, and can't see to remember or find this elusive function.

推荐答案

好了,你看,这个人是很难的,因为PHP阵列功能页面上的一般描述不说,这个函数你在找什么

Well, you see, this one is hard, because the general description on the PHP array functions page does not say that this function does what you're looking for.

但是,你可以使用 ksort()数组排序,然后用这个: array_values​​()。从页从PHP手册:

But you can sort the array using ksort(), and then use this: array_values() . From the page from the PHP manual:

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

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

这篇关于PHP对齐阵列键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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