NoobNewbie Posted July 2, 2007 Share Posted July 2, 2007 Hi! I'm new to php, and I was wondering how can we call variables thorugh a for cycle, for example. Allow me to explain: $var1 = 'Hello'; $var2 = 'Hello again'; for($a=1;$a<=2;++$a){ echo $var.$a; } I thought that it would echo the two variables, but it's echoing 12 instead. I believe its some syntax error, because in other languages we can do that. So, how can we do that? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 2, 2007 Share Posted July 2, 2007 I think what you're after is: <?php $var1 = 'Hello'; $var2 = 'Hello again'; for($a=1;$a<=2;++$a){ $var = 'var'.$a; echo $$var; } ?> Quote Link to comment 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.