使用当前索引中的下一个索引值创建数组(使用无序索引)的最佳方法是什么.我试图使用next()但没有帮助.我的意思是:
Array
(
[0] => a
[8] => b
[2] => c
[7] => d
[9] => e
[11] => f
)
所以,我希望这些数据像下面的数组一样
Array
(
[0] => Array
(
[current] => a
[next] => b
)
[8] => Array
(
[current] => b
[next] => c
)
[2] => Array
(
[current] => c
[next] => d
)
[7] => Array
(
[current] => d
[next] => e
)
[9] => Array
(
[current] => e
[next] => f
)
[11] => Array
(
[current] => f
[next] =>
)
)
什么是最快的方式来做到这一点.
最佳答案 UPDATE
对于无序数组
$newarray = array();
$length = count($oldarray);
for($i = 0; $i < $length ; ++$i)
{
$newarray[] = array('current'=>current($oldarray),'next'=>next($oldarray));
}