bugcoder Posted September 19, 2012 Share Posted September 19, 2012 Hi, This might be basics of php but i haven't come across this situation before. $sumQuarter_1 = 121; $sumQuarter_2 = 223; ........so on later somewhere in code i have variable having just 1, 2 etc only e.g $quarterNumber = 2; now how can I get the value dynamically from $sumQuarter_2 as I can't use echo $sumQuarter_$quarterNumber; ------------- I hope my question is clear enough. Quote Link to comment https://forums.phpfreaks.com/topic/268547-making-variable-from-variables/ Share on other sites More sharing options...
bugcoder Posted September 19, 2012 Author Share Posted September 19, 2012 found solution echo ${"sumQuarter_{$quarterNumber}"}; Quote Link to comment https://forums.phpfreaks.com/topic/268547-making-variable-from-variables/#findComment-1379209 Share on other sites More sharing options...
requinix Posted September 19, 2012 Share Posted September 19, 2012 The solution is an array, not variable variables. $sumQuarter = array( 1 => 121, 2 => 223 ); Quote Link to comment https://forums.phpfreaks.com/topic/268547-making-variable-from-variables/#findComment-1379211 Share on other sites More sharing options...
ManiacDan Posted September 19, 2012 Share Posted September 19, 2012 +1 to what requinix said. You're making your variables wrong in the first place, that's why the solution is so convoluted. Quote Link to comment https://forums.phpfreaks.com/topic/268547-making-variable-from-variables/#findComment-1379240 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.