2013-06-23 10:56
浏览 27


Helle there, There is a post: I have the same question, but instead of count, I want to echo it. I have this code in xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root xmlns:xsi="">

And this as PHP:

$xml = simplexml_load_file("include/gamemodes.xml");

foreach ($xml->Row->children() as $child)
    echo $child->getName(), ": ", $child, "<br>";

It only echo's the first row and none more, how can I make it to echo multiple rows, the result should be:

ModeNumber: 1
Mode: online
ModeNumber: 2
Mode: mmorpg

Sorry for my bad english.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqroktbn005028 2013-06-23 11:25

    You are iterating over the children of the first Row element only. Try this instead:

    /* Iterate over all 'Row' elements */
    foreach ($xml->Row as $row) 
        /* For each 'Row' iterate over all children elements */
        foreach ($row as $child) 
            printf("%s: %s
    ", $child->getName(), $child);

    See, also, this short demo.

    解决 无用
    打赏 举报

相关推荐 更多相似问题