Search code examples
phparrayssimplexmlvar-dump

How to obtain the value of an array exposed in var_dump from a SimpleXMLElement return?


I sorry for the aparently easy question for all you experienced developers. But I can´t obtain the answer in any place. So I´ll try here. Maybe help other guy someday.

$xml = new SimpleXMLElement($object->ExecutarXMLResult->any);
var_dump($xml);

My var_dump is that:

object(SimpleXMLElement)#5 (2) { ["listatomador"]=> array(104) { [0]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(3) { ["id_pessoa"]=> string(4) "5251" ["nm_pessoa"]=> string(28) "Wilson" ["nr_cnpj_cpf"]=> string(14) "1" } } [1]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(3) { ["id_pessoa"]=> string(3) "939" ["nm_pessoa"]=> string(46) "Grupo" ["nr_cnpj_cpf"]=> string(14) "5" } }

So I you can see, I know there is 104 units of "listatomador" as explained in array(104). But how could I obtain it in my code? I tried every way and nothing.


Solution

  • Iterating over each index ..

    foreach ( $xml as $item ) {
           // ... 
    }