あなたが使用することができCachingIterator
ますextract
$a = array(2,1,8,18,10);
$it = new CachingIterator(new ArrayIterator($a));
$t1 = array();
foreach ( $it as $v ) {
$var = array("no" => $v,"to" => 0);
if ($it->hasNext()) {
$var["to"] = $it->getInnerIterator()->current();
}
$t1[] = $var;
}
extract($t1, EXTR_PREFIX_ALL, "t1");
var_dump($t1_0,$t1_1,$t1_2,$t1_3,$t1_4);
出力
array (size=2)
'no' => int 2
'to' => int 1
array (size=2)
'no' => int 1
'to' => int 8
array (size=2)
'no' => int 8
'to' => int 18
array (size=2)
'no' => int 18
'to' => int 10
array (size=2)
'no' => int 10
'to' => int 0