homepage Welcome to WebmasterWorld Guest from 54.204.249.184
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How can i display output from dynamically generated variables
Nani22




msg:4423495
 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

 

incrediBILL




msg:4423915
 1:05 am on Mar 2, 2012 (gmt 0)

Try defining the vars like this:

${"previous_dsgn_{$i}"} = "this is a test for var $i";

eelixduppy




msg:4423919
 1:10 am on Mar 2, 2012 (gmt 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved