开发者

looping through xml nodes where a type is "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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜