Skip to content

Instantly share code, notes, and snippets.

@justenj
Last active March 16, 2016 17:07
Show Gist options
  • Save justenj/381fcc7c96229a6f0ee4 to your computer and use it in GitHub Desktop.
Save justenj/381fcc7c96229a6f0ee4 to your computer and use it in GitHub Desktop.
$xml = json_decode(json_encode(simplexml_load_file($data_file)), true);
$data = [];
foreach ($xml as $key => $many) {
foreach ($many as $one) {
foreach ($one as $item) {
$attributes = $item['@attributes'];
if (isset($attributes['id'])) {
$data[$key][$attributes['id']] = array_merge($attributes, $item);
} else {
$data[$key][] = array_merge($attributes, $item);
}
}
}
unset($xml[$key]);
}
unset($xml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment