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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.