If I initialize variable values:
$some_variable1 = 0;
$some_variable2 = 0;
... etc
And if I only have the variable name as a string "some_variable1" received as input from a different file, how do I then modify that variable without directly referring to that name by using the following:
$some_variable1++;
$some_variable1 = ... ;
I'm trying to modify variables based on the text strings I receive from a file. I don't want to make options for all possible variable names called because I want to receive any kind of variable name and if it doesn't exist, I want it to be created, then modified accordingly.
I'm basically trying to do something like this.
$some_variable1 = 0;
$string = "some_variable1"
"$some_variable1" = "$some_variable1" + 1;
print $some_variable; // outputs 1
though this is obviously incorrect code.
manipulating variables
Moderator: General Moderators
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
Sounds like you need variable variables. Read this and see if it helps:
http://us4.php.net/language.variables.variable
http://us4.php.net/language.variables.variable
COOL !!! Didnt know abt this. Thanks neophyte.
Code: Select all
<?php
$some_variable1 = 5;
$string = "e;some_variable1"e;;
$$string++;
echo $some_variable1;
?>-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact: