johnsmith153 Posted October 24, 2008 Share Posted October 24, 2008 Any idea why this doesn't work? What should I be doing? //xxx.php?Name1=Jim&Name2=Bob&Name3=Dave for($i=1; $i < 10; $i++) { $getName="Name"+$i; echo $i.": ".$_GET[$getName]."<br>"; } $_GET['$getName'] obviously doesn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/130015-echo-_getvariablename/ Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 you want a . not a + for($i=1; $i < 10; $i++) { $getName="Name".$i; echo $i.": ".$_GET[$getName]."<br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/130015-echo-_getvariablename/#findComment-674079 Share on other sites More sharing options...
johnsmith153 Posted October 24, 2008 Author Share Posted October 24, 2008 How obvious, what an idiot I am. Although it still doesn't work. is $_GET[$getName] an actual possibility? Quote Link to comment https://forums.phpfreaks.com/topic/130015-echo-_getvariablename/#findComment-674080 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 Yeah, it should work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/130015-echo-_getvariablename/#findComment-674081 Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 dunno what your intentions are, but it would be a lot easier to just do : foreach($_GET as $key => $val) { echo "$key : $val <br/>"; } Though you should definitely sanitize your vars no matter what (your method or mine or any). Quote Link to comment https://forums.phpfreaks.com/topic/130015-echo-_getvariablename/#findComment-674109 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.