kegham
kegham

Reputation: 11

Echo specified array content

I have a JSON file which iam using ( file_get_contents ) from a url, to extract the values to a good formatted way. The problem is that i need to echo out a specific value content but failed to do that. So here is the piece of code iam providing here may be if someone would like to help me out to do it.

Array
(
    [type] => result
    [data] => Array
        (
            [0] => Array
                (
                    [title] => My Radio Name
                    [song] => Artist Name - Song Name
                    [track] => Array
                        (
                            [artist] => Artist Name
                            [title] => Song Name
                            [album] => Unknown
                            [royaltytrackid] => 0
                            [id] => 542
                            [playlist] => Array
                                (
                                    [id] => 45
                                    [title] => ALL SONGS
                                )
                               .....

SO i need to echo out [artist] AND [title] Which will be echoed as: Artist Name | Song Name

Thanks in advance any help would be appreciated :)

Upvotes: 1

Views: 61

Answers (1)

Marcin
Marcin

Reputation: 1494

Depends on format of your json but below code should work:

foreach ( $json['data'] as $entry ){

    foreach ( $entry['track'] as $track ){

       echo $track['artist'] ." | ".  $track['title'] ."<br/>";

    }
}

Upvotes: 1

Related Questions