开发者

SimpleXML node attribute loop

开发者 https://www.devze.com 2022-12-18 05:25 出处:网络
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.

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

精彩评论

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

关注公众号