Traverse XML array in PHP

Asked

Viewed 265 times

0

Hello. I have this path that is a position of a array of an XML response, and I’m taking the IDcli.

I can’t make a foreach along this array and show the IDcli.

$xml = simplexml_load_string($obj);

$xml->sis->cont->Clis->Cli[0]->IDcli;

I tried just the for, but it only counts until 9:

for ( $j = 0; $j < count( $xml->sis->cont->Clis->Cli[$j]->IDcli ); $j++ ) {
  echo "<br>".$xml->sis->cont->Clis->Cli[$j]->IDcli;
}
  • Have you tried foreach ($xml->sis->cont->Clis->Cli as $id) { echo $id->IDcli }?

  • I put it down like I did, thank you.

1 answer

0


I did that, and it worked.

$tuas_tags = $xml->sis->cont->Clis->Cli[0]->IDcli;

foreach ( $tuas_tags as $tua_tag )
{
    echo "<br>".$tua_tag->IDcli;

}

Thank you who tried.

  • But it doesn’t just take the IDcli of the first array index?

  • True, but with that I can do the rest.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.