Welcome to WebmasterWorld Guest from 54.198.222.129

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)



for($i=1;$i<=5;$i++)
{
$previous_dsgn_{$i}=$_POST["previous_dsgn_$i"];
$previous_place_{$i}=$_POST["previous_place_$i"];
$previous_year_{$i}=$_POST["previous_year_$i"];
$previous_dsgn_{$i}="$previous_dsgn_$i";
$previous_place_{$i}="$previous_place_$i";
$previous_year_{$i}="$previous_year_$i";
}
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)

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



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)

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



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month