I am working with SOAP and converting the response to an array, however, theres multiple levels of nesting/parent arrays that make further working with the data a pain in the butt namely because the array names change, etc
So, I'm taking my soap response and running it through the following to get it as an array:
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($response);
return json_decode(json_encode($xml), TRUE);
When I print_r that output I get the following horror:
Array
(
[soapBody] => Array
(
[ns1getMultiplePeakSensorDataResponse] => Array
(
[ns1ArrayOfISXCSensorDataSet] => Array
(
[ns2ISXCSensorDataSet] => Array
(
[0] => Array
(
[ns2ISXCSensorData] => Array
(
[ns2timeStamp] => 2017-02-21T23:23:59Z
[ns2units] => W
[ns2value] => 490
[ns2ISXCValueType] => INTEGER
)
[ns2ISXCElementID] => B16b483_nbSNMPEncBAF04BFE_OUTPUT_POWER_TOTAL_1
)
[1] => Array
(
[ns2ISXCSensorData] => Array
(
[ns2timeStamp] => 2017-02-21T23:23:59Z
[ns2units] => W
[ns2value] => 510.0
[ns2ISXCValueType] => UNKNOWN
)
[ns2ISXCElementID] => B16b483_nbSNMPEncBAF04BFE_OUTPUT_POWER_TOTAL_2
)
)
)
)
)
)
...and what I've LOVE to end up with is:
Array
(
[0] => Array
(
[ns2ISXCSensorData] => Array
(
[ns2timeStamp] => 2017-02-21T23:23:59Z
[ns2units] => W
[ns2value] => 490
[ns2ISXCValueType] => INTEGER
)
[ns2ISXCElementID] => B16b483_nbSNMPEncBAF04BFE_OUTPUT_POWER_TOTAL_1
)
[1] => Array
(
[ns2ISXCSensorData] => Array
(
[ns2timeStamp] => 2017-02-21T23:23:59Z
[ns2units] => W
[ns2value] => 510.0
[ns2ISXCValueType] => UNKNOWN
)
[ns2ISXCElementID] => B16b483_nbSNMPEncBAF04BFE_OUTPUT_POWER_TOTAL_2
)
)
I can brute force this with:
$i=0;
while($i != 4) {
$response = call_user_func_array('array_merge', $response);
$i++;
}
...but there are incidents where the nesting level isn't always four layers so it's not really a solution.
I've given a whack at quite a few solutions from the interwebs any nothing really preserves the final inner array, it either overwrites the keys down to a single result or only returns a series of values in a non-associative array.
Any thoughts or input would be greatly appreciated.
Thank you =)