iterator_to_array — 将迭代器复制到数组
数组 iterator_to_array ( Traversable $iterator [, bool $use_keys = true ] )
它适用于所有可 遍历接口,但为什么我在以下代码中输入错误:
$data = array(
0 => array(
0 => 1,
),
1 => array(
0 => 2,
),
2 => array(
0 => 3,
1 => 4,
2 => 5,
),
3 => array(
0 => 6,
),
4 => array(
0 => 7,
),
);
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
echo PHP_EOL, iterator_count($it); // 7 total correct
echo PHP_EOL, implode(iterator_to_array($it)); //745 instead of 1234567
echo PHP_EOL, implode(iterator_to_array($it, true)); //745 instead of 1234567
但
foreach($it as $v)
{
echo $v ;
}
输出
1234567