0

I am currently messing around with iTunes Api and have ran into a problem with the returning process of albums track list returning the first result as the actual album data instead of the tracklist.

$loop['artist_name'] = $counted[$x]->artistName;
$loop['album_id'] = $counted[$x]->collectionId;
$loop['album_name'] = $counted[$x]->collectionName;
$loop['track_number'] = $counted[$x]->trackCount;
$loop['artwork_url'] = $counted[$x]->artworkUrl100;
$loop['copyright'] = $counted[$x]->copyright;
$loop['genre'] = $counted[$x]->primaryGenreName;
$loop['release_date'] = $counted[$x]->releaseDate;

$data_b = file_get_contents('https://itunes.apple.com/lookup?id='.$loop['album_id'].'&entity=song');
$response_ab = json_decode($data_b);
print '<pre>';
print_r($response_ab);
print '</pre>';

The above portion for print_r returns the following data.

[results] => Array
    (
        [0] => stdClass Object
            (
                [wrapperType] => collection
            )

        [1] => stdClass Object
            (
                [wrapperType] => track
            )

Then continues onward down the track list, how can I remove the first [0] option from my loop? It appears this only returns the album name anyway when I am trying to get the tracklist.

4

1 Answer 1

1

I didn't test the below code however it should work.

$data_b = file_get_contents('https://itunes.apple.com/lookup?id='.$loop['album_id'].'&entity=song');
$response_ab = json_decode($data_b);

$count = $response_ab->results;
$arr = count($count);
for($a = 1; $a < $arr; $a++) {

// do some cool stuff here

}
Sign up to request clarification or add additional context in comments.

1 Comment

Have you just "done all of the work" for the OP after complaining about it? (I don't support your variable naming choices.) Please explain your code-only solution. Every posted answer should endeavor to educate thousands of future researchers.

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.