I've searched for an answer to this specific issue and didn't find one - my apologies if I overlooked something... here's my issue... I'm building an integration between two databases, and I'm coding in PHP. I get an XML response from the source API, then need to extract specific data values from that response and add them to an array for insertion into the sink database through its API. I can get to the data values I need from the source, but when I try to add them into the array format the sink requires, I'm getting an array containing the Key/value pair instead of just the value.
Here's a short snippet of the code I'm using to extract the data I need to build the array:
foreach($invoiceResponse->operation->result->data->sodocument as $sodoc){
$invoice = array("Invoice_ID"=>$sodoc->DOCNO, "Invoice_Date"=>$sodoc->WHENPOSTED)
}
The resulting array looks like this:
{"Invoice_ID":{"0":"SI-000525"},"Invoice_Date":{"0":"03\/22\/2018"}}
And what I want is this:
{"Invoice_ID":"SI-000525","Invoice_Date":"03\/22\/2018"}
Here's a snap of the xml format from the source:
<response>
<control>
<status>success</status>
</control>
<operation>
<authentication>
<status>success</status>
<sessiontimestamp>2018-04-12T08:14:55-07:00</sessiontimestamp>
</authentication>
<result>
<status>success</status>
<function>readByQuery</function>
<data listtype="sodocument" count="1" totalcount="1" numremaining="0" resultId="">
<sodocument>
<PROJECT>GER-0318-DIG-005</PROJECT>
<CONTACT.COMPANYNAME>FFF Production Service</CONTACT.COMPANYNAME>
<TYPE_OF_INVOICE>Bill in Full</TYPE_OF_INVOICE>
<WHENPOSTED>04/10/2018</WHENPOSTED>
<STATE>Pending</STATE>
</sodocument>
...
I convert the xml to an array in php using this:
$response = simplexml_load_string($xml_response);
I can extract the data in a simple statement, for example, a line of code like this:
$query = "DOCHDRID = '".$sodoc->DOCID."'";
results in
DOCHDRNO = 95
so the data is getting extracted correctly here, but when I use this same syntax to add these values to an array I'm experiencing the issue as described above.
I'm sure it's something easy, but I would greatly appreciate any help! Thanks!