I have an xml which contains orders . I would like to separate into row for each order . Here is a sample of my xml
I have done foreach loop and I got the Name, Id total price, and name of orders . But I also want to get the count of orders and individual prices per item .
<Result>
<TotalPages>1</TotalPages>
<CurrentPage>1</CurrentPage>
<Submissions>
<Submission Id="80930936" Department="First Department">
<Form Id="3905379">
<Status>published</Status>
<Version>1</Version>
</Form>
<Date>2019.08.02 03:20:22</Date>
<DeviceDate>2019.08.02 03:20:13</DeviceDate>
<FirstName>Julius</FirstName>
<LastName>Tuliao</LastName>
<ResponseID>a847d685b701752f-1564715956621</ResponseID>
<No.>00001</No.>
<SubmissionNumber>00001</SubmissionNumber>
<Sections>
<Section>
<Name>Employee</Name>
<Screens>
<Screen>
<Name>Employee</Name>
<Responses>
<Response Guid="E181A1574F9564269160F9525634030D075B805D">
<Label>Code</Label>
<Value>180935</Value>
<Type>Text Box</Type>
</Response>
<Response Guid="03DF1EDA1840BAF1469CB951B45812B38BEFA11A">
<Label>Name</Label>
<Value>Qwe, Angel.</Value>
<Type>Text Box</Type>
</Response>
</Responses>
</Screen>
</Screens>
</Section>
<Section>
<Name>Order</Name>
<Screens>
<Screen>
<Name>Order</Name>
<ResponseGroups>
<ResponseGroup Guid="FFD9E21F5A28ED44C041168A62418D32B084AC7C">
<Response Guid="FFD9E21F5A28ED44C041168A62418D32B084AC7C">
<Label>Order</Label>
<Value>Bitter Gourd</Value>
<Type>Value List</Type>
</Response>
<Section>
<Name>Order (Detail)</Name>
<Screens>
<Screen>
<Name>Order</Name>
<Responses>
<Response Guid="6973C81303383F84F254D74733BC8D7ECA27140B">
<Label>Type</Label>
<Value>LUNCH</Value>
<Type>Text Box</Type>
</Response>
<Response Guid="044EE6155F024EFBB24098E26CDEBED62E2A6B09">
<Label>Price</Label>
<Value>60</Value>
<Type>Integer</Type>
</Response>
<Response Guid="0EDCA8076D0A6269751B72FADA078440B08E49E2">
<Label>Price Out</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="F5F846CA7C04C26408DEDDDFA621508F8E37DC53">
<Label>Price Staff</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="9A9805F1E1CD7F981AC1284A6CEE62DC2F4A392B">
<Label>Rice</Label>
<Value>With Rice</Value>
<Type>Value List</Type>
</Response>
<Response Guid="451225EDFA312637E276D4AAB8A87756622B54D0">
<Label>Cup</Label>
<Value/>
<Type>Value List</Type>
</Response>
<Response Guid="1C59DD971ED3A0F855FFFD10DE14F80856F0011A">
<Label>Deduction</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="C0F854A0FFB4E6993BEE203D73CFC994F75E011A">
<Label>Deduction Coffee</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="62C47C8DB8B7C58C5783EAB0CFFA43D6D541BF76">
<Label>No. of Order</Label>
<Value>1</Value>
<Type>Integer</Type>
</Response>
<Response Guid="974F7E2E1D7002DC884C54038A264291EE1521D6">
<Label>Total Price</Label>
<Value>60.00</Value>
<Type>Calculation</Type>
</Response>
</Responses>
</Screen>
</Screens>
</Section>
</ResponseGroup>
<ResponseGroup Guid="FFD9E21F5A28ED44C041168A62418D32B084AC7C">
<Response Guid="FFD9E21F5A28ED44C041168A62418D32B084AC7C">
<Label>Order</Label>
<Value>RICE</Value>
<Type>Value List</Type>
</Response>
<Section>
<Name>Order (Detail)</Name>
<Screens>
<Screen>
<Name>Order</Name>
<Responses>
<Response Guid="6973C81303383F84F254D74733BC8D7ECA27140B">
<Label>Type</Label>
<Value>EXTRA</Value>
<Type>Text Box</Type>
</Response>
<Response Guid="044EE6155F024EFBB24098E26CDEBED62E2A6B09">
<Label>Price</Label>
<Value>10</Value>
<Type>Integer</Type>
</Response>
<Response Guid="0EDCA8076D0A6269751B72FADA078440B08E49E2">
<Label>Price Out</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="F5F846CA7C04C26408DEDDDFA621508F8E37DC53">
<Label>Price Staff</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="9A9805F1E1CD7F981AC1284A6CEE62DC2F4A392B">
<Label>Rice</Label>
<Value/>
<Type>Value List</Type>
</Response>
<Response Guid="451225EDFA312637E276D4AAB8A87756622B54D0">
<Label>Cup</Label>
<Value/>
<Type>Value List</Type>
</Response>
<Response Guid="1C59DD971ED3A0F855FFFD10DE14F80856F0011A">
<Label>Deduction</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="C0F854A0FFB4E6993BEE203D73CFC994F75E011A">
<Label>Deduction Coffee</Label>
<Value/>
<Type>Integer</Type>
</Response>
<Response Guid="62C47C8DB8B7C58C5783EAB0CFFA43D6D541BF76">
<Label>No. of Order</Label>
<Value>1</Value>
<Type>Integer</Type>
</Response>
<Response Guid="974F7E2E1D7002DC884C54038A264291EE1521D6">
<Label>Total Price</Label>
<Value>10.00</Value>
<Type>Calculation</Type>
</Response>
</Responses>
</Screen>
</Screens>
</Section>
</ResponseGroup>
</ResponseGroups>
</Screen>
</Screens>
</Section>
<Section>...</Section>
</Sections>
</Submission>
</Submissions>
</Result>
$xml=simplexml_load_string($xml) or die("Error: Cannot create object");
$totalPages = $xml->TotalPages;
$currentPage = $xml->CurrentPage;
foreach ($xml->Submissions->Submission as $submission) {
$no = (array) $submission->{'No.'};
$xmlToArray[$no[0]] = array();
foreach($submission->Sections->Section as $section)
{
$name = (array) $section->Name;
$xmlToArray[$no[0]][$name[0]] = array();
if($section->Name != "Order"){
foreach($section->Screens->Screen as $screen) {
foreach($screen->Responses->Response as $response) {
$label = (array) $response->Label;
$value = (array) $response->Value;
if(isset($value[0])) {
$xmlToArray[$no[0]][$name[0]][$label[0]] = $value[0];
} else {
$xmlToArray[$no[0]][$name[0]][$label[0]] = '';
}
}
}
}
else{
foreach($section->Screens->Screen as $screen) {
$i = 0;
foreach($screen->ResponseGroups->ResponseGroup as $responseGroup) {
$i++;
$label = (array) $responseGroup->Response->Label;
$value = (array) $responseGroup->Response->Value;
if(isset($value[0])) {
$xmlToArray[$no[0]][$name[0]][$i] = $value[0];
} else {
$xmlToArray[$no[0]][$name[0]][$i] = '';
}
}
}
}
}
}
Once i loop it and display the orders I expect the output to be separated by item by currently it is displayed by submission no