Alpha_Link Posted October 21, 2009 Share Posted October 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/ Share on other sites More sharing options...
ldb358 Posted October 21, 2009 Share Posted October 21, 2009 if ($sortby == "artist") { $title = "Artist"; } elseif ($sortby == "album") { $title = "Album"; } but i dont get exactly what you mean or are trying to do Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/#findComment-940848 Share on other sites More sharing options...
mikesta707 Posted October 21, 2009 Share Posted October 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/#findComment-940850 Share on other sites More sharing options...
Alpha_Link Posted October 21, 2009 Author Share Posted October 21, 2009 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/#findComment-940855 Share on other sites More sharing options...
mikesta707 Posted October 21, 2009 Share Posted October 21, 2009 alright that seems fine. echo $sortby and see what you get Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/#findComment-940856 Share on other sites More sharing options...
Alpha_Link Posted October 21, 2009 Author Share Posted October 21, 2009 Yep, working fine. Quote Link to comment https://forums.phpfreaks.com/topic/178413-variable-inside-of-variable/#findComment-940859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.