如何在PHP中重新索引数组的值?

时间:2009-09-25 13:16:45

标签: php arrays key

Array (
    [id] => 3
    [user_id] => 1
    [clan_id] => 1
    [date] => 2009-09-24 09:02:05
    [skill1rank] => 1
    [skill1lvl] => 2376
    [skill1xp] => 1804229942
    [skill2rank] => 53
    [skill2lvl] => 99
    [skill2xp] => 120510105
    [skill3rank] => 5526
    [skill3lvl] => 99
    [skill3xp] => 21581237
    [skill4rank] => 622
    ...
    [skill21xp] => 38458116
    [skill22rank] => 184
    [skill22lvl] => 99
    [skill22xp] => 22217059
    [skill23rank] => 5267
    [skill23lvl] => 99
    [skill23xp] => 13396733
    [skill24rank] => 101
    [skill24lvl] => 99
    [skill24xp] => 15724235
    [skill25rank] => 903
    [skill25lvl] => 99
    [skill25xp] => 13373505
) 

我想重命名为$array[0]$array[1]等的密钥。

我该怎么做?


谢谢,Silentghost。工作得很好。 :)

3 个答案:

答案 0 :(得分:8)

答案 1 :(得分:0)

使用array_values:

array_values( [id] => 3 [user_id] => 1 [clan_id] => 1 [date] => 2009-09-24 09:02:05    
[skill1rank] => 1 [skill1lvl] => 2376 [skill1xp] => 1804229942 [skill2rank] => 53 
[skill2lvl] => 99 [skill2xp] => 120510105 [skill3rank] => 5526 [skill3lvl] => 99 
[skill3xp] => 21581237 [skill4rank] => 622 ... [skill21xp] => 38458116 [skill22rank] => 
184 [skill22lvl] => 99 [skill22xp] => 22217059 [skill23rank] => 5267 [skill23lvl] => 99 
[skill23xp] => 13396733 [skill24rank] => 101 [skill24lvl] => 99 [skill24xp] => 15724235 
[skill25rank] => 903 [skill25lvl] => 99 [skill25xp] => 13373505 );

答案 2 :(得分:0)

这是我的解决方案:

$array = array(
    "id" => 3,
    "user_id" => 1,
    "clan_id" => 1,
    "date" => "2009-09-24 09:02:05",
    "skill1rank" => 1,
    "skill1lvl" => 2376,
    "skill1xp" => 1804229942,
    "skill2rank" => 53,
    "skill2lvl" => 99,
    "skill2xp" => 120510105,
    "skill3rank" => 5526,
    "skill3lvl" => 99,
    "skill3xp" => 21581237,
    "skill4rank" => 622,
);

$newArray = array();
foreach($array as $key => $value) {
    $newArray[] = $value;
}