Creech Posted February 12, 2007 Share Posted February 12, 2007 first sry for my bad english <input type="text" name="menge<?PHP echo $i ?>" value="<?php echo $menge{$i}; ?>"> this code is in a loop as you see i'm creating a name for that inputbox with a variable number creating with a loop 0 to x so the name is menge0 menge1 menge2 and so on as value i want $menge0 $menge1 ... but i don't get it to work... i just can't figure out how to creat a variable $menge with a variable number at the end... like $variable$i maybe someone can help me ty Creech Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/ Share on other sites More sharing options...
btherl Posted February 12, 2007 Share Posted February 12, 2007 Have you looked at arrays? If you REALLY want variable variable names, you can do this: $varname = "menge{$i}"; echo print "{$varname} is {$$varname}\n"; Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182550 Share on other sites More sharing options...
Wireless102 Posted February 12, 2007 Share Posted February 12, 2007 first sry for my bad english <input type="text" name="menge<?PHP echo $i ?>" value="<?php echo $menge{$i}; ?>"> this code is in a loop as you see i'm creating a name for that inputbox with a variable number creating with a loop 0 to x so the name is menge0 menge1 menge2 and so on as value i want $menge0 $menge1 ... but i don't get it to work... i just can't figure out how to creat a variable $menge with a variable number at the end... like $variable$i maybe someone can help me thank you Creech instead of $menge{$i} use $menge.$i Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182551 Share on other sites More sharing options...
sasa Posted February 12, 2007 Share Posted February 12, 2007 try <?php $a1 = 'sasa'; $a2 ='bls'; $a3 = 'asdf'; for ($i=1; $i<4; $i++) echo ${'a'.$i},"<br />\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182553 Share on other sites More sharing options...
Creech Posted February 12, 2007 Author Share Posted February 12, 2007 instead of $menge{$i} use $menge.$i that does not work i get nothing in return... i try to use the other hint's but until now no <? for ($i=0; $i<$number; $i++){ ?> <p>Menge: <input type="text" name="menge<?PHP echo $i ?>" value="$menge0"> <?php } ?> i just try again to explain ^^ the page is loaded... the name is created now i want the name as a variable into the value part so that after reloading the page that what was typed into the inputbox apears again... anything else that could help to understand my problem? ty Creech Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182556 Share on other sites More sharing options...
btherl Posted February 12, 2007 Share Posted February 12, 2007 Try this: <? for ($i=0; $i<$number; $i++){ $varname = "menge{$i}"; ?> <p>Menge: <input type="text" name="menge<?php echo $i; ?>" value="<?php echo $$varname; ?>"> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182560 Share on other sites More sharing options...
Creech Posted February 12, 2007 Author Share Posted February 12, 2007 thx man that works problem solved Quote Link to comment https://forums.phpfreaks.com/topic/38133-solved-variable-variable-name/#findComment-182564 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.