m3tsys
m3tsys

Reputation: 3969

How to get some php multidimensional arrays?

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

Answers (4)

user142162
user142162

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

Jan Dragsbaek
Jan Dragsbaek

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

Senad Meškin
Senad Meškin

Reputation: 13756

foreach($artist['tags'] as $key => $value)
 echo $value['name'] . ' ';

this will loop through array and will write tags into response

Upvotes: 1

Brad
Brad

Reputation: 163301

foreach ($artist['tags'] as $tag) {
    echo $tag['name'];
}

I think this is what you are asking for...

Upvotes: 1

Related Questions