Re: adding text to a variable name
| From: | Gyozo Papp | Date: | Tue, 01 May 2001 21:29:01 +0000 |
| Subject: | Re: adding text to a variable name | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-51029@lists.php.net to get a copy of this message | ||
From: "Jamie Saunders" <webprogramming@jamie-s.co.uk>
Subject: [PHP] adding text to a variable name
> Is it possible to add text onto the end of a variable name?
> e.g. to add the word 'code' onto the variable $field so it would be $fieldcode
I think you want to do it in an automatic way for each variable which satisfies a prescribed
condition, so you may use a for / while statement
for ( ; ; ) {
GLOBALS[$old_name . "_put_your_own_postfix_here"] = GLOBALS[$old_name];
}
or with variable variables:
for ( ; ; ) {
$new_name = $old_name . "_put_your_own_postfix_here";
$$new_name = $$old_name;
}
but if you know the name of variables exactly, the simplest solution is already posted. $var_code =
$var;