1

I have this array that i used json_decode to create. This is my code:

$obj = json_decode($json);
$results = $obj->{"results"}; // This selects the results section
echo $results[artistName];

$results is the array

The array looks like this:

array(1) { 
   [0]=> object(stdClass)#5 (8) { 
      ["wrapperType"]=> string(6) "artist"    
      ["artistType"]=> string(6) "Artist" 
      ["artistName"]=> string(5) "Human"
      ["artistLinkUrl"]=> string(56) "https://itunes.apple.com/us/artist/human/id35761368?uo=4" 
      ["artistId"]=> int(35761368) 
      ["amgArtistId"]=> int(1173165) 
      ["primaryGenreName"]=> string(3) "Pop" 
      ["primaryGenreId"]=> int(14) 
   } 
}

But it does not echo anything. Please help.

2 Answers 2

4

It's still an object, so you need to access the key like this.

echo $results[0]->artistName;
Sign up to request clarification or add additional context in comments.

Comments

1
echo $results[0]->artistName

Notice, u have array of stdClasses

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.