开发者

looping through xml nodes where a type is "Array"

开发者 https://www.devze.com 2022-12-10 03:35 出处:网络
Im having some trouble looping through some xml data. The xml file is structured like this: <users type=\"array\">

Im having some trouble looping through some xml data.

The xml file is structured like this:

<users type="array">
 −<user>
   <id>14527576</id>
  </user>
 −<user>
   <id>14527576</id>
  </user>
 −<user>
   <id>14527576</id>
  </user>

My php to loop through it looks like this

$xml = simplexml_load_string($rawxml);
foreac开发者_运维百科h($xml->users AS $key){
    $id = $key->user->{"id"};

But its not throwing errors, or returning anything


Users is your root element. You need just to enumerate it.

$xml = simplexml_load_string( $rawxml );

foreach($xml as $user){
  print $user->id . '<br />';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消