0

XML and foreach question

the Title is not issued with unfortunately why? where did I fail can someone help me?

foreach ($xml->data->SONGHISTORY->SONG as $dj) {
     echo $dj->PLAYEDAT;
     echo $dj->TITLE;
 }
3
  • Could you please clarify the question? What do you see from your foreach loop? You should see something like 1392152578Djerem & Shana P - Back To You (T-M-S Remix)1392152331Devel in the Mix by ... Commented Feb 11, 2014 at 22:40
  • Wrap your dump in pre tags so you can actually see the levels of the array Commented Feb 11, 2014 at 22:40
  • Any chance you can provide an example of the XML? Commented Feb 11, 2014 at 22:43

1 Answer 1

2

To me, it seems simply that there is no data node in the XML. From your var_dump output, you should be using this...

foreach ($xml->SONGHISTORY->SONG as $dj) {
    echo $dj->PLAYEDAT, ' ', $dj->TITLE, PHP_EOL;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yep, I was about to point out that he was using data in his foreach but not up above under his var_dump
Yep, remember: "Don't mention the root element." :)

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.