<?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);
- Output for 5.6.0 - 5.6.27, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- object(SimpleXMLElement)#1 (2) {
["result"]=>
object(SimpleXMLElement)#2 (7) {
["LabelNumber"]=>
string(12) "oa0021148274"
["Scans"]=>
object(SimpleXMLElement)#3 (5) {
["0"]=>
object(SimpleXMLElement)#5 (11) {
["Type"]=>
string(1) "P"
["Courier"]=>
string(3) "020"
["Description"]=>
string(9) "Picked up"
["Date"]=>
string(19) "06/11/2014 18:58:14"
["Name"]=>
string(9) "Cape Town"
["Franchise"]=>
string(3) "CPT"
["Status"]=>
string(3) "PPP"
["StatusDescription"]=>
string(25) "Your parcel was picked up"
["CompanyInfo"]=>
object(SimpleXMLElement)#10 (11) {
["contactName"]=>
object(SimpleXMLElement)#12 (0) {
}
["company"]=>
object(SimpleXMLElement)#13 (0) {
}
["address1"]=>
object(SimpleXMLElement)#14 (0) {
}
["address2"]=>
object(SimpleXMLElement)#15 (0) {
}
["address3"]=>
object(SimpleXMLElement)#16 (0) {
}
["address4"]=>
object(SimpleXMLElement)#17 (0) {
}
["address5"]=>
object(SimpleXMLElement)#18 (0) {
}
["address6"]=>
object(SimpleXMLElement)#19 (0) {
}
["address7"]=>
object(SimpleXMLElement)#20 (0) {
}
["address8"]=>
object(SimpleXMLElement)#21 (0) {
}
["comment"]=>
object(SimpleXMLElement)#22 (0) {
}
}
["UploadDate"]=>
string(10) "07/11/2014"
["Signature"]=>
object(SimpleXMLElement)#11 (0) {
}
}
["1"]=>
object(SimpleXMLElement)#6 (11) {
["Type"]=>
string(1) "T"
["Courier"]=>
string(3) "020"
["Description"]=>
string(8) "Pretoria"
["Date"]=>
string(19) "06/11/2014 19:04:30"
["Name"]=>
string(9) "Cape Town"
["Franchise"]=>
string(3) "CPT"
["Status"]=>
string(3) "PRY"
["StatusDescription"]=>
string(55) "Your parcel is currently in transit between our depots."
["CompanyInfo"]=>
object(SimpleXMLElement)#11 (11) {
["contactName"]=>
object(SimpleXMLElement)#22 (0) {
}
["company"]=>
object(SimpleXMLElement)#21 (0) {
}
["address1"]=>
object(SimpleXMLElement)#20 (0) {
}
["address2"]=>
object(SimpleXMLElement)#19 (0) {
}
["address3"]=>
object(SimpleXMLElement)#18 (0) {
}
["address4"]=>
object(SimpleXMLElement)#17 (0) {
}
["address5"]=>
object(SimpleXMLElement)#16 (0) {
}
["address6"]=>
object(SimpleXMLElement)#15 (0) {
}
["address7"]=>
object(SimpleXMLElement)#14 (0) {
}
["address8"]=>
object(SimpleXMLElement)#13 (0) {
}
["comment"]=>
object(SimpleXMLElement)#12 (0) {
}
}
["UploadDate"]=>
string(10) "07/11/2014"
["Signature"]=>
object(SimpleXMLElement)#10 (0) {
}
}
["2"]=>
object(SimpleXMLElement)#7 (11) {
["Type"]=>
string(1) "T"
["Courier"]=>
string(3) "011"
["Description"]=>
string(30) "Pretoria Depot Scan "
["Date"]=>
string(19) "10/11/2014 06:56:34"
["Name"]=>
string(8) "Pretoria"
["Franchise"]=>
string(3) "PRY"
["Status"]=>
string(3) "O01"
["StatusDescription"]=>
string(52) "Your parcel has been received in the Pretoria depot."
["CompanyInfo"]=>
object(SimpleXMLElement)#10 (11) {
["contactName"]=>
object(SimpleXMLElement)#12 (0) {
}
["company"]=>
object(SimpleXMLElement)#13 (0) {
}
["address1"]=>
object(SimpleXMLElement)#14 (0) {
}
["address2"]=>
object(SimpleXMLElement)#15 (0) {
}
["address3"]=>
object(SimpleXMLElement)#16 (0) {
}
["address4"]=>
object(SimpleXMLElement)#17 (0) {
}
["address5"]=>
object(SimpleXMLElement)#18 (0) {
}
["address6"]=>
object(SimpleXMLElement)#19 (0) {
}
["address7"]=>
object(SimpleXMLElement)#20 (0) {
}
["address8"]=>
object(SimpleXMLElement)#21 (0) {
}
["comment"]=>
object(SimpleXMLElement)#22 (0) {
}
}
["UploadDate"]=>
string(10) "10/11/2014"
["Signature"]=>
object(SimpleXMLElement)#11 (0) {
}
}
["3"]=>
object(SimpleXMLElement)#8 (11) {
["Type"]=>
string(1) "T"
["Courier"]=>
string(3) "013"
["Description"]=>
string(7) "Onboard"
["Date"]=>
string(19) "10/11/2014 07:51:19"
["Name"]=>
string(8) "Pretoria"
["Franchise"]=>
string(3) "PRY"
["Status"]=>
string(3) "ONB"
["StatusDescription"]=>
string(52) "Onboard - the parcel is onboard the Courier vehicle."
["CompanyInfo"]=>
object(SimpleXMLElement)#11 (11) {
["contactName"]=>
object(SimpleXMLElement)#22 (0) {
}
["company"]=>
string(13) "Home Delivery"
["address1"]=>
string(12) "44 suikerbos"
["address2"]=>
string(7) "lydiana"
["address3"]=>
string(1) "o"
["address4"]=>
object(SimpleXMLElement)#21 (0) {
}
["address5"]=>
object(SimpleXMLElement)#20 (0) {
}
["address6"]=>
object(SimpleXMLElement)#19 (0) {
}
["address7"]=>
object(SimpleXMLElement)#18 (0) {
}
["address8"]=>
object(SimpleXMLElement)#17 (0) {
}
["comment"]=>
object(SimpleXMLElement)#16 (0) {
}
}
["UploadDate"]=>
string(10) "10/11/2014"
["Signature"]=>
object(SimpleXMLElement)#10 (0) {
}
}
["4"]=>
object(SimpleXMLElement)#9 (11) {
["Type"]=>
string(1) "D"
["Courier"]=>
string(3) "013"
["Description"]=>
string(18) "Signature Obtained"
["Date"]=>
string(19) "10/11/2014 09:47:05"
["Name"]=>
string(8) "Pretoria"
["Franchise"]=>
string(3) "PRY"
["Status"]=>
string(3) "YES"
["StatusDescription"]=>
string(67) "Signature Obtained - Your parcel has been delivered and signed for."
["CompanyInfo"]=>
object(SimpleXMLElement)#10 (11) {
["contactName"]=>
string(8) "philimon"
["company"]=>
string(13) "Home Delivery"
["address1"]=>
string(12) "44 suikerbos"
["address2"]=>
string(7) "lydiana"
["address3"]=>
string(1) "o"
["address4"]=>
object(SimpleXMLElement)#11 (0) {
}
["address5"]=>
object(SimpleXMLElement)#16 (0) {
}
["address6"]=>
object(SimpleXMLElement)#17 (0) {
}
["address7"]=>
object(SimpleXMLElement)#18 (0) {
}
["address8"]=>
object(SimpleXMLElement)#19 (0) {
}
["comment"]=>
object(SimpleXMLElement)#20 (0) {
}
}
["UploadDate"]=>
string(10) "10/11/2014"
["Signature"]=>
string(70) "http://api.fastway.org/signatures/0312408478f58b8b1d685a148089960f.jpg"
}
}
["Signature"]=>
string(70) "http://api.fastway.org/signatures/0312408478f58b8b1d685a148089960f.jpg"
["DistributedTo"]=>
string(60) "Cape Town "
["DistributedDate"]=>
string(9) "8/08/2014"
["Reference"]=>
object(SimpleXMLElement)#4 (0) {
}
["IsOnforward"]=>
string(1) "0"
}
["generated_in"]=>
string(5) "155ms"
}
preferences:
144.85 ms | 423 KiB | 190 Q