donglan7594 2013-10-16 15:44
浏览 50
已采纳

如何通过索引获取xml元素

I have an xml file that contains a list of elements. I want to retrieve a specific element by index. I looked around for a while and didn't find anything that worked for me.

I would have thought this would work, but it doesn't:

echo($xml->children()[0]);

I'm not very experienced in php, coming from a C# background, so any help is appreciated.

  • 写回答

1条回答 默认 最新

  • dongping4901 2013-10-16 16:17
    关注

    Array dereferencing was added in PHP 5.4 so your code will (probably) work with that version.

    If you're stuck with an older version, simply try this

    $children = $xml->children();
    echo $children[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部