重排 PHP 数组键名

22

我有一个数组:

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开始排序?我知道有一个函数,但我的头脑已经混乱了。sort函数不能满足我的需求,因为它们会重新排列值,而我需要它们被保留。

 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);
1个回答

62

我认为你正在寻找array_values

$arr = array_values($arr);


看起来还应用了 trim =) array_map('trim', ...) 到极致。 - Rudie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接