Reputation: 3969
How to call all the tags at once?
I curently do something like this:
$artist['tags']['0']['name'];
$artist['tags']['1']['name'];
// and so on for all 5 (0-4)
[tags] => Array
(
[0] => Array
(
[name] => hip-hop
[url] => http://www.last.fm/tag/hip-hop
)
[1] => Array
(
[name] => romanian
[url] => http://www.last.fm/tag/romanian
)
[2] => Array
(
[name] => romanian hip-hop
[url] => http://www.last.fm/tag/romanian%20hip-hop
)
[3] => Array
(
[name] => rap
[url] => http://www.last.fm/tag/rap
)
[4] => Array
(
[name] => hip hop
[url] => http://www.last.fm/tag/hip%20hop
)
)
Upvotes: 0
Views: 100
Reputation:
You can use a foreach
loop to iterate through all the tags of an artist:
$tags = array();
foreach ($artist['tags'] as $tag)
{
$tags[] = $tag['name'];
}
echo implode(', ', $tags);
Upvotes: 3
Reputation: 8101
Use foreach and iterate over them.
It seems like you want to use this:
foreach($artist['tags'] as $key => $value)
echo $value['name'] . ', ';
Upvotes: 1
Reputation: 13756
foreach($artist['tags'] as $key => $value)
echo $value['name'] . ' ';
this will loop through array and will write tags into response
Upvotes: 1
Reputation: 163301
foreach ($artist['tags'] as $tag) {
echo $tag['name'];
}
I think this is what you are asking for...
Upvotes: 1