I have a XML file, where some elements will be empty. The issue is, that this code, creates an empty array, if the element is empty. Som for the XML example below, the result from JSON_DECODE would be:
I have tried setting depth to two, with no luck.
[26272] => Array (
[productname] => Some product name
[ean] => Array ( )
)
Example XML:
<item>
<productname>Some product name</productname>
<ean></ean>
</item>
The code i´m using:
$xml = simplexml_load_file($url);
$json = json_encode($xml,JSON_PRETTY_PRINT);
$products = json_decode($json, TRUE);
<ean></an>
is an empty list.simplexml_load_file()
, I don't see any that will make it load<ean></ean>
as a string node rather than an element.