Take the 2-minute tour ×

I have the following code :

$results = $Q->get_posts($args);

foreach ($results as $r) {
    print $r['trackArtist'];

This is the output :


My question is, if trackArtist is an array, why can't I run the implode function like this :

$artistString = implode(" , ", $r['trackArtist']);



Yes, it is a string indeed, but from the other side it leaves as an array so I assumed it arrives as an array here also. There must be some processing done in the back.

Any idea how I can extract the information, for example from : ["DUKY","LOQUACE"]

to get :


Thanks for your time

share|improve this question
This seems not to be an array but maybe an object? –  Zeal Apr 4 '13 at 14:28
Why do you think that trackArtist is array? –  hjpotter92 Apr 4 '13 at 14:28
Try var_dump($r['trackArtist']); instead of print(); to check if it is actually an array. –  Gerald Schneider Apr 4 '13 at 14:28
What makes you think trackArtist is an array? –  Mark Baker Apr 4 '13 at 14:28
echo "<pre>"; print_r($results); echo "</pre>"; whats the Output ? –  Fawad Ghafoor Apr 4 '13 at 14:29
show 1 more comment

3 Answers

up vote 1 down vote accepted

It's probably a JSON string. You can do this to get the desired result:

$a = json_decode($r['trackArtist']); // turns your string into an array
$artistString = implode(', ', $a); // now you can use implode
share|improve this answer
Thank you !! It works ! –  Gabriel Gray Apr 4 '13 at 15:03
You're welcome. –  Mischa Apr 4 '13 at 15:03
add comment

It looks like it's not actually an array; it's the string '["DUKY","LOQUACE"]' An array would be printed as Array. You can confirm this with:

share|improve this answer
add comment

To me content of $r['trackArtist'] is NOT an array. Just regular string or object. Instead of print use print_r() or var_dump() to figure this out and then adjust your code to work correctly with the type of object it really is.

share|improve this answer
I guess he meant $r['trackArtist'] is an array, not 'trackArtist'. –  Mido Apr 4 '13 at 14:42
yep. I refered to that. Edited –  Marcin Orlowski Apr 4 '13 at 14:44
add comment

Your Answer


