开发者

SimpleXML node attribute loop

I am having a little problem how can I turn the following code into a whileloop , I know how to create a whileloop but working with the simpleXML code seems to throw me of course.

my code get me either the first or last attribute开发者_开发知识库 but I need all of them.

can any one help

<?php foreach (current($xml->xpath('/*/gig[last()]'))->attributes() as $attr) {}?>


I don't know what your actual code looks like, but this works:

$xml = simplexml_load_string(
    '<gigs>
        <gig a="1" b="2"/>
    </gigs>'
);

foreach (current($xml->xpath('/*/gig[last()]'))->attributes() as $k => $v)
{
    var_dump($k,$v);
}

Each attribute is listed, both its name ($k) and its value ($v)


while ($cur = each(...))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜