tags:

views:

147

answers:

2

Hi ,

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) {}?>
A: 
while ($cur = each(...))
mst
+1  A: 

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)

Josh Davis