Jump to content

Variable Inside Of Variable?


Alpha_Link

Recommended Posts

I don't know what to properly call what I'm trying to do but hopefully you get the idea.

 

Anyway, here is a variable that I'm trying to edit:

$song["artist"]

 

But i want it to be this:

$song["$sortby"]

 

and $sortby is:

if ($sortby = "artist") {
$title = "Artist";
} elseif ($sortby = "album") {
$title = "Album";
}

 

However, it isn't working and printing any data?  What could be wrong?

Link to comment
https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/
Share on other sites

what you are using is an array. a good tutorial on arrays

 

try doing it without quotes, IE

echo $song[$sortby];

 

but I have a feeling your array isn't structred like you think it is. do a print_r($song) if it still doesn't work, and post the results

This what I get:

 

Array ( [id] => 280 [filename] => D:\Newgrounds\Ocarina Medley.mp3 [diskid] => 0 [flags] => NNNNNNNNNN [songtype] => S [status] => 0 [weight] => 92 [balance] => 0.0324330642002451 [date_added] => 2009-06-11 12:24:52 [date_played] => 2009-10-19 09:43:09 [date_artist_played] => 2009-10-20 21:26:28 [date_album_played] => 2009-10-20 21:18:19 [date_title_played] => 2009-10-19 15:59:10 [duration] => 252082 [artist] => Newgrounds - Setu-Firestorm [title] => Ocarina Medley [album] => Newgrounds [label] => [pline] => [trackno] => 1 [composer] => [isrc] => [catalog] => [upc] => [feeagency] => [albumyear] => 2007 [genre] => Game [website] => [buycd] => [info] => This track can be found at http://www.newgrounds.com/audio/view.php?id=1699615&sub=74275 [lyrics] => [picture] => newgrounds.jpg [count_played] => 146 [count_requested] => 25 [last_requested] => 2009-10-07 19:56:24 [count_performances] => 2026 [xfade] => [bpm] => 0 [mood] => [rating] => 0 [overlay] => no [playlimit_count] => 0 [playlimit_action] => none [songrights] => broadcast [adz_listid] => 0 [requestid] => 0 )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.