Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/07/2011, 16:00
Avatar de linux_car
linux_car
 
Fecha de Ingreso: agosto-2010
Mensajes: 18
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: recorre un array multidimencional traido de un xml

este fue lo que encontre y lo adapte a mi codigo pero me da un error


Código PHP:
<?php
$myArray 
=$xml simplexml_load_file('test.xml');

$iterator = new RecursiveArrayIterator($myArray);
iterator_apply($iterator'traverseStructure', array($iterator));

function 
traverseStructure($iterator) {
   
    while ( 
$iterator -> valid() ) {

        if ( 
$iterator -> hasChildren() ) {
       
            
traverseStructure($iterator -> getChildren());
           
        }
        else {
            echo 
"<br>".$iterator -> key() . ' : ' $iterator -> current();   
        }

        
$iterator -> next();
    }
}
?>
y el error es :


Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Overloaded object of type SimpleXMLElement is not compatible with RecursiveArrayIterator' in C:\wamp\www\fpdf\EstudioPracticas\ArrayRecursivo.p hp:4 Stack trace: #0 C:\wamp\www\fpdf\EstudioPracticas\ArrayRecursivo.p hp(4): ArrayIterator->__construct(Object(SimpleXMLElement)) #1 {main} thrown in C:\wamp\www\fpdf\EstudioPracticas\ArrayRecursivo.p hp on line 4