2009-09-25 62 views
1
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]如何在PHP中重新索引數組的值?

我會如何呢?


謝謝,Silentghost。很好地工作。 :)

+1

您可以格式化你的文字,它會更容易閱讀轉儲或您的陣列。 – 2009-09-25 13:21:07

+1

投票結束,太局部。我們是否真的需要複製php手冊? – markus 2009-09-25 13:21:15

+1

爲什麼你需要閱讀它,呂克? – SilentGhost 2009-09-25 13:21:29

回答

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); 
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; 
}