我正在尝试遍历此数组并删除任何类型的排序:(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] 吗?