Darkness Soul Posted December 5, 2006 Share Posted December 5, 2006 Yo,Is possible to mount variable name with the code? My case: I have a form with the input fields named by a prefixe and the line id, and, recover it with import_request_variables() function.Exemple:[code]form.php(...) -- ordened by the sqlinput name="detail241" value=""input name="detail23" value=""(...)action.php(...)import_request_variables ( "p" , "var_" ) ;print $var_detail241 ;(...)[/code]This $var_detail241, I haven't a way to know its number, but I need its value, all I have is a for with all Id posted and the name $var_detail, so, how do I, if its possible, to make an $var_detail+$id to make my numered variable?Thank you.D.Soul Link to comment https://forums.phpfreaks.com/topic/29568-mount-variable-names/ Share on other sites More sharing options...
trq Posted December 5, 2006 Share Posted December 5, 2006 Im sorry, but I can't make any sense of your post. At all. Link to comment https://forums.phpfreaks.com/topic/29568-mount-variable-names/#findComment-135711 Share on other sites More sharing options...
Stooney Posted December 5, 2006 Share Posted December 5, 2006 What he's trying to say is if he can declare a variable who's name is based on other variables. Ex:[code]$num=4;$var$num="text";echo $var4; //outputs 'text'[/code]of course that doesn't work. As far as I know it's not possible. Maybe someone might know of something after I put it in English. Link to comment https://forums.phpfreaks.com/topic/29568-mount-variable-names/#findComment-135715 Share on other sites More sharing options...
kenrbnsn Posted December 5, 2006 Share Posted December 5, 2006 What you're looking for are called [url=http://www.php.net/manual/en/language.variables.variable.php]variable variables[/url].A better way of doing this is to use arrays. In the form:[code]<input name="detail[241]" value=""><input name="detail[23]" value="">[/code]In action.php[code]<?phpif isset($_POST['detail']) foreach($_POST as $key => $val) echo '$_POST[' . $key . '] = ' . $val . "<br>\n";?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/29568-mount-variable-names/#findComment-135726 Share on other sites More sharing options...
Darkness Soul Posted December 6, 2006 Author Share Posted December 6, 2006 Thank you, this are very useful!I used just one time a long ago this form array and get missed it.. :) I'm happy plus now!D.Soul Link to comment https://forums.phpfreaks.com/topic/29568-mount-variable-names/#findComment-136079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.