2

I am using Last.fm get event by venue API call. It returns an XML with multiple objects

print_r($xml)

This is the result

SimpleXMLElement Object
(
    [events] => SimpleXMLElement Object
        (
           [event] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                           ....
                        )
                    [1] => SimpleXMLElement Object
                        (
                           ....
                        )
                    ....
                )
        )
)
SimpleXMLElement Object
(
     .............
     .............
)

I can apply foreach loop like this

foreach($xml->events->event as $data) {
    ...
}

But it returns only data from first object. How can I get or loop data from other objects?

2 Answers 2

2

You need to call children() function

foreach($xml->events->children() as $data) {
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

events is an object with one member, event. I guess you can do

foreach($xml->events->event as $data) {
    ...
}

Mind you that again, $data will be an object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.