Zend_Config_Xml strange behaviour

Cyber Hacker

New Member
I have a strange problem with Zend_Config_Xml. Here is an example. With this xml file https://gist.github.com/883465this code: $config = new Zend_Config_Xml('config.xml'); var_dump($config->get('elements')->get('element')->toArray()); gives: array(2) { [0]=> array(2) { ["a"]=> array(1) { ["attr"]=> string(2) "at" } ["e"]=> array(3) { [0]=> array(1) { ["attr"]=> string(2) "at" } [1]=> array(1) { ["attr"]=> string(2) "at" } [2]=> array(1) { ["attr"]=> string(2) "at" } } } [1]=> array(2) { ["a"]=> array(1) { ["attr"]=> string(2) "at" } ["e"]=> array(3) { [0]=> array(1) { ["attr"]=> string(2) "at" } [1]=> array(1) { ["attr"]=> string(2) "at" } [2]=> array(1) { ["attr"]=> string(2) "at" } } } } with this xml file https://gist.github.com/883469it gives: array(2) { ["a"]=> array(1) { ["attr"]=> string(2) "at" } ["e"]=> array(3) { [0]=> array(1) { ["attr"]=> string(2) "at" } [1]=> array(1) { ["attr"]=> string(2) "at" } [2]=> array(1) { ["attr"]=> string(2) "at" } } } and I expect: array(1) { [0]=> array(2) { ["a"]=> array(1) { ["attr"]=> string(2) "at" } ["e"]=> array(3) { [0]=> array(1) { ["attr"]=> string(2) "at" } [1]=> array(1) { ["attr"]=> string(2) "at" } [2]=> array(1) { ["attr"]=> string(2) "at" } } } } This is tricky when you want to iterate over elements $config = new Zend_Config_Xml('config.xml'); foreach($config->get('elements')->get('element') as $element); which is fine if there are more then one elements, but if you have only one, you'll end up iterating over element children! Any idea? EDIT:I came up with an ugly workaround:if (0 !== $config->get('elements')->get('element')) { // }This helps me to identify if there is more then one elements under elements tag.Very ugly.Anithing smarter?
 
Top