Skip to content

Instantly share code, notes, and snippets.

@vollyimnetz
vollyimnetz / simpleXmlToArray
Created December 9, 2020 15:05 — forked from yeroon/simpleXmlToArray
Converts a simpleXML element into an array. Preserves attributes and everything.
/**
* Converts a simpleXML element into an array. Preserves attributes and everything.
* You can choose to get your elements either flattened, or stored in a custom index that
* you define.
* For example, for a given element
* <field name="someName" type="someType"/>
* if you choose to flatten attributes, you would get:
* $array['field']['name'] = 'someName';
* $array['field']['type'] = 'someType';
* If you choose not to flatten, you get: