<?php
$json = '{
"result": {
"LabelNumber": "oa0021148274",
"Scans": [{
"Type": "P",
"Courier": "020",
"Description": "Picked up",
"Date": "06/11/2014 18:58:14",
"Name": "Cape Town",
"Franchise": "CPT",
"Status": "PPP",
"StatusDescription": "Your parcel was picked up",
"CompanyInfo": {
"contactName": "",
"company": "",
"address1": "",
"address2": "",
"address3": "",
"address4": "",
"address5": "",
"address6": "",
"address7": "",
"address8": "",
"comment": ""
},
"UploadDate": "07/11/2014",
"Signature": ""
}, {
"Type": "T",
"Courier": "020",
"Description": "Pretoria",
"Date": "06/11/2014 19:04:30",
"Name": "Cape Town",
"Franchise": "CPT",
"Status": "PRY",
"StatusDescription": "Your parcel is currently in transit between our depots.",
"CompanyInfo": {
"contactName": "",
"company": "",
"address1": "",
"address2": "",
"address3": "",
"address4": "",
"address5": "",
"address6": "",
"address7": "",
"address8": "",
"comment": ""
},
"UploadDate": "07/11/2014",
"Signature": ""
}, {
"Type": "T",
"Courier": "011",
"Description": "Pretoria Depot Scan ",
"Date": "10/11/2014 06:56:34",
"Name": "Pretoria",
"Franchise": "PRY",
"Status": "O01",
"StatusDescription": "Your parcel has been received in the Pretoria depot.",
"CompanyInfo": {
"contactName": "",
"company": "",
"address1": "",
"address2": "",
"address3": "",
"address4": "",
"address5": "",
"address6": "",
"address7": "",
"address8": "",
"comment": ""
},
"UploadDate": "10/11/2014",
"Signature": ""
}, {
"Type": "T",
"Courier": "013",
"Description": "Onboard",
"Date": "10/11/2014 07:51:19",
"Name": "Pretoria",
"Franchise": "PRY",
"Status": "ONB",
"StatusDescription": "Onboard - the parcel is onboard the Courier vehicle.",
"CompanyInfo": {
"contactName": "",
"company": "Home Delivery",
"address1": "44 suikerbos",
"address2": "lydiana",
"address3": "o",
"address4": "",
"address5": "",
"address6": "",
"address7": "",
"address8": "",
"comment": ""
},
"UploadDate": "10/11/2014",
"Signature": ""
}, {
"Type": "D",
"Courier": "013",
"Description": "Signature Obtained",
"Date": "10/11/2014 09:47:05",
"Name": "Pretoria",
"Franchise": "PRY",
"Status": "YES",
"StatusDescription": "Signature Obtained - Your parcel has been delivered and signed for.",
"CompanyInfo": {
"contactName": "philimon",
"company": "Home Delivery",
"address1": "44 suikerbos",
"address2": "lydiana",
"address3": "o",
"address4": "",
"address5": "",
"address6": "",
"address7": "",
"address8": "",
"comment": ""
},
"UploadDate": "10/11/2014",
"Signature": "http://api.fastway.org/signatures/0312408478f58b8b1d685a148089960f.jpg"
}],
"Signature": "http://api.fastway.org/signatures/0312408478f58b8b1d685a148089960f.jpg",
"DistributedTo": "Cape Town ",
"DistributedDate": "8/08/2014",
"Reference": "",
"IsOnforward": "0"
},
"generated_in": "155ms"
}';
function array2xml($array, $xml = false){
if($xml === false){
$xml = new SimpleXMLElement('<result/>');
}
foreach($array as $key => $value){
if(is_array($value)){
array2xml($value, $xml->addChild($key));
} else {
$xml->addChild($key, $value);
}
}
return $xml;
}
$data = array2xml(json_decode($json, true), false);
var_dump($data);
preferences:
26.41 ms | 402 KiB | 5 Q