递归迭代器在具有索引元素的多维数组上进行迭代


RecursiveIteratorIterator on multidimensional array with indexed elements

我正在尝试遍历这个数组并删除任何类型的排序:(1,2,3,4等)

array( 0 => array ( 'col1' => 'value', 'col2' => 'value', 'col3' => 'value', 'col4' => value', 'col5' => 'value', 'col6' => array ( 'string' => array ( 'col7' => 'value' , 'col8' => 'value'), ), ), 
    1 => array ( 'col1' => 'value', 'col2' => 'value', 'col3' => 'value', 'col4' => array ( ), 'col5' => 'value', 'col6' => array ( 'string' => array ( ), ),  ),
     2 => array ( 'col1' => 'value', 'col2' => 'value', 'col3' => 'value', 'col4' => array ( ), 'col5' => 'value', 'col6' => array ( 'string' => array ( ), ), ), )

使用以下代码:

    foreach($json['orders']['cnr_output_ship_to_header'] as $header)
{

   $iterator_orders = new 'IteratorIterator(new 'ArrayIterator($header));
    $iterator_guests = new 'RecursiveIteratorIterator(new'RecursiveArrayIterator($header['guests']['cnr_output_guest_detail']));
    $iterator_items = new 'RecursiveIteratorIterator(new 'RecursiveArrayIterator($header['items']['cnr_output_item_detail']));

$orders = (array)iterator_to_array($iterator_orders,true); 
$guests = (array)iterator_to_array($iterator_guests,true);
$items = (array)iterator_to_array($iterator_items,true);


pdo_insert('cnr_output_ship_to_header', (array)$orders);
pdo_insert('cnr_output_guest_detail', (array)$guests);
pdo_insert('cnr_output_item_detail', (array)$items);

}

,但它正在删除元素0和1。知道如何包含[0]和[1]吗?

我放弃了JSON,使用了simpleXML,因为每个都能像上面提到的那样工作。