Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How can i display output from dynamically generated variables

9:00 am on Mar 1, 2012 (gmt 0)

New User

joined:Mar 1, 2012
posts: 1
votes: 0

echo "$previous_dsgn_$i,$previous_place_$i,$previous_year_$i";

guys i am getting output array6,array6,array6 instaed of entered details,how can i get output that i entered
1:05 am on Mar 2, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
votes: 88

Try defining the vars like this:

${"previous_dsgn_{$i}"} = "this is a test for var $i";
1:10 am on Mar 2, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
votes: 0

Hi and welcome to webmasterworld!

First off, you should be echoing the variables within the for loop, not outside of it. This still won't help, however, because I believe the syntax for the variable variable would be something along the lines of this:

echo "${previous_dsgn_$i},${previous_place_$i},${previous_year_$i}";

But whenever you use variable variables there has to be a real good reason why you would want to do something like this. So, why are you implementing it like this as oppose to, say, using an array to hold these values?