2012-01-10 128 views
8

我有此數組:重新排列數組的鍵PHP

Array 
(
[15] =>  13.1 

[16] =>  Mark one answer 

[19] => You see a car on the hard shoulder of a motorway with a HELP pennant displayed. This means the driver is most likely to be 

[20] => a disabled person first aid trained 

[21] => a foreign visitor 

[22] => a rescue patrol person 

[25] => DES s15, HC r278); 

我如何得到它的鍵值從0排序? 得到這個:我知道有一個函數,但我的頭被燒燬,排序函數不符合我的需要,因爲他們重新排列值,我需要它們被保存。

Array 
(
[0] => 13.1 

[1] => Mark one answer 

[2] => You see a car on the hard shoulder of a motorway with a HELP pennant displayed. This means the driver is most likely to be 

[3] => a disabled person first aid trained 

[4] => a foreign visitor 

[5] => a rescue patrol person 

[6] => DES s15, HC r278); 

回答

31

我認爲你正在尋找array_values

$arr = array_values($arr);

+1

:)我討厭當我胸圍我的頭就像一個小時知道這是簡單而不得不來這裏問。非常感謝。 – Sebastian 2012-01-10 02:09:47

+0

它看起來像一個'trim'被應用=)'array_map('trim',...)'到最大值。 – Rudie 2012-01-10 02:12:32

+0

@Sebastian不用擔心 – Ben 2012-01-10 05:23:49