0

Hi I've asked this before but didn't get a correct answer. I am trying to get the Tracks to print from the stdObject. I've tried many possible answers but nothing worked apart from using:

var_dump("Track Title: " . $response->Items->Item->Tracks->Disc->Track[0]->_);

But this only works if you know how many tracks there are for certain CD, I am calling 500 ASIN's at once. So basically I would like to parse the Tracks array into a String

  [Items] => stdClass Object
       (
        [Request] => stdClass Object
        (
            [IsValid] => True
            [ItemLookupRequest] => stdClass Object
                (
                    [IdType] => ASIN
                    [ItemId] => B000002OGL
                    [ResponseGroup] => Tracks
                    [VariationPage] => All
                )

        )

    [Item] => stdClass Object
        (
            [ASIN] => B000002OGL
            [Tracks] => stdClass Object
                (
                    [Disc] => stdClass Object
                        (
                            [Track] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [_] => Mustang Sally
                                            [Number] => 1
                                        )

                                    [1] => stdClass Object
                                        (
                                            [_] => Take Me To The River
                                            [Number] => 2
                                        )

                                    [2] => stdClass Object
                                        (
                                            [_] => Chain Of Fools
                                            [Number] => 3
                                        )

                                    [3] => stdClass Object
                                        (
                                            [_] => The Dark End Of The Street
                                            [Number] => 4
                                        )

                                    [4] => stdClass Object
                                        (
                                            [_] => Destination: Anywhere
                                            [Number] => 5
                                        )

                                    [5] => stdClass Object
                                        (
                                            [_] => I Can't Stand The Rain
                                            [Number] => 6
                                        )

                                    [6] => stdClass Object
                                        (
                                            [_] => Try A Little Tenderness
                                            [Number] => 7
                                        )

                                    [7] => stdClass Object
                                        (
                                            [_] => Treat Me Right
                                            [Number] => 8
                                        )

                                    [8] => stdClass Object
                                        (
                                            [_] => Do Right Woman Do Right Man
                                            [Number] => 9
                                        )

                                    [9] => stdClass Object
                                        (
                                            [_] => Mr. Pitiful
                                            [Number] => 10
                                        )

                                    [10] => stdClass Object
                                        (
                                            [_] => I Never Loved A Man
                                            [Number] => 11
                                        )

                                    [11] => stdClass Object
                                        (
                                            [_] => In The Midnight Hour
                                            [Number] => 12
                                        )

                                    [12] => stdClass Object
                                        (
                                            [_] => Bye Bye Baby
                                            [Number] => 13
                                        )

                                    [13] => stdClass Object
                                        (
                                            [_] => Slip Away
                                            [Number] => 14
                                        )

                                )

                            [Number] => 1
                        )
                )
        )
         )
        )
3
  • I don't understand where the problem is. If you just need to loop all the tracks of a disk, just use a nested foreach loop. First loop "Item" (or, to be honest, Item->tracks directly), then tracks and then disc. Foreach Track, then get the field "_" to get the song name and do whatever you need with that, either append that to a string or do what you need. How are all the results collected? Commented Feb 16, 2016 at 11:41
  • can you tell us the exact output you need..? it would be more helpful if you specify the output you need. Commented Feb 16, 2016 at 11:53
  • Hi @SahilGulati this is what I'm trying to achieve stackoverflow.com/questions/35339328/… Commented Feb 16, 2016 at 12:41

1 Answer 1

2

you can do

foreach($response->Items->Item->Tracks->Disc->Track as $track){
  echo "Track Title: ". $track->_;// or track title
}
Sign up to request clarification or add additional context in comments.

3 Comments

This will actually echo the number, not the track title. for the track title you problably meant track->_, right?
Still whenever I want to add the data to magento which my code does it returns in the logs that the "stdObject" cant be converted into a string.
I am not an expert in magento and since you have posted another question hope you find your answer.

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.