Jump to content

Mount variable names


Darkness Soul

Recommended Posts

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 sql
input 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

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

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]<?php
if 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.