我正在尝试遍历此数组并删除任何类型的排序:(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]?
答案 0 :(得分:0)
我抓了JSON并使用了simpleXML,foreach就像上面提到的一样。