I'm having trouble iterating an array that contains other arrays inside it.
foreach ($resultPedidos as $key => $rs) {
$cont++;
foreach ($resultadoItemPedidos as $key => $rows) {
if ($rs['order_number'] == $rows['order_number']) {
// XML A SER PASSADO PARA O WS.
$params = array(
'order_number' => $rs['order_number'],
'order_type' => $rs['order_type'],
'order_priority' => $rs['order_priority'],
'order_client_name' => $rs['order_client_name'],
'order_client_phone' => $rs['order_client_phone'],
'order_client_code' => $rs['order_client_code'],
'order_client_cpf_cnpj' => $rs['order_client_cpf_cnpj'],
'order_client_address' => $rs['order_client_address'],
'order_client_address_number' => $rs['order_client_address_number'],
'order_client_complement' => $rs['order_client_complement'],
'order_client_district' => $rs['order_client_district'],
'order_client_city' => $rs['order_client_city'],
'order_client_state' => $rs['order_client_state'],
'order_client_cep' => $rs['order_client_cep'],
'order_exped_name' => $rs['order_exped_name'],
'order_exped_field' => $rs['order_exped_field'],
'order_exped_date' => $rs['order_exped_date'],
'Order_ERPWMS' => $rs['Order_ERPWMS'],
'order_invoices' => array(
'OrderIdadnvoice' => array(
'invoice_ERPWMS' => $rs['invoice_ERPWMS'],
'invoice_receiver_id' => $rs['invoice_receiver_id'],
'invoice_receiver_name' => $rs['invoice_receiver_name'],
'invoice_sender_id' => $rs['invoice_sender_id'],
'invoice_sender_name' => $rs['invoice_sender_name'],
'invoice_danfe' => $rs['invoice_danfe'],
'invoice_number' => $rs['invoice_number'],
'invoice_serie' => $rs['invoice_serie'],
'invoice_value' => $rs['invoice_value'],
)),
'order_items' => array(
'OrderItem' => array(
'items_ERPWMS' => $rows['items_ERPWMS'],
'item_danfe' => $rows['item_danfe'],
'item_picking_number' => $rows['item_picking_number'],
'item_picking_type' => $rows['item_picking_type'],
'item_quantity' => $rows['item_quantity'],
'item_sku_barcode' => $rows['item_sku_barcode'],
'item_stock_position' => $rows['item_stock_position']
)),
);
The problem: I need to pass this array that will generate an XML from the web service side, it's a relationship items - > order, in that case if a request has more than one item it creates another identical array by changing only the OrderItems array
An example of how you would like it to be:
<order_number>000000</order_number>
<order_type>DOMICÍLIO</order_type>
<order_priority>1</order_priority>
<order_client_name>AAAA</order_client_name>
<order_client_phone>00000</order_client_phone>
<order_client_code>00000</order_client_code>
<order_client_cpf_cnpj>000000</order_client_cpf_cnpj>
<order_client_address>RUA </order_client_address>
<order_client_address_number>1</order_client_address_number>
<order_client_complement>LETRA A</order_client_complement>
<order_client_district>DIST INDUSTRIAL PIRES II</order_client_district>
<order_client_city>EXTREMA</order_client_city>
<order_client_state>MINAS GERAIS</order_client_state>
<order_client_cep>37640000</order_client_cep>
<order_exped_name>AAAA</order_exped_name>
<order_exped_field></order_exped_field>
<order_exped_date>01/02/2018</order_exped_date>
<order_erpwms>11111</order_erpwms>
<order_invoices>
<invoice_number>11111</invoice_number>
<invoice_serie>5 </invoice_serie>
<invoice_danfe></invoice_danfe>
<invoice_value>111</invoice_value>
<invoice_sender_name> LTDA</invoice_sender_name>
<invoice_sender_id>000000</invoice_sender_id>
<invoice_receiver_name>AAAA</invoice_receiver_name>
<invoice_receiver_id>11111</invoice_receiver_id>
<invoice_ERPWMS>1</invoice_ERPWMS>
</order_invoices>
<order_items>
<item_picking_type>UN</item_picking_type>
<item_picking_number>0</item_picking_number>
<item_sku_barcode>111111</item_sku_barcode>
<item_quantty>5</item_quantty>
<item_danfe />
<items_ERPWMS>002301</items_ERPWMS>
<item_picking_type>UN</item_picking_type>
<item_picking_number>0</item_picking_number>
<item_sku_barcode>323232</item_sku_barcode>
<item_quantty>2</item_quantty>
<item_danfe />
</order_items>
I'm using two select
, but the result it repeats for each item plus the same request.